Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify cargo features #117

Merged
merged 2 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 12 additions & 36 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,24 @@ categories = ["wasm"]
crate-type = ["cdylib", "rlib"]

[features]
default = ["arrow1", "parquet_supported_compressions", "reader", "writer"]
arrow1 = ["arrow", "parquet"]
default = ["arrow1", "all_compressions", "reader", "writer"]
arrow1 = ["dep:arrow", "dep:parquet"]
arrow2 = ["dep:arrow2", "dep:parquet2"]
reader = []
writer = []
debug = ["console_error_panic_hook", "clap"]

parquet_supported_compressions = [
"parquet/brotli",
"parquet/flate2",
"parquet/snap",
"parquet/zstd",
]

parquet2_supported_compressions = [
"parquet2/brotli",
"parquet2/gzip",
"parquet2/lz4_flex",
"parquet2/snappy",
"parquet2/zstd",
]
brotli = ["parquet?/brotli", "parquet2?/brotli"]
gzip = ["parquet?/flate2", "parquet2?/gzip"]
snappy = ["parquet?/snap", "parquet2?/snappy"]
zstd = ["parquet?/zstd", "parquet2?/zstd"]
# LZ4 not yet supported on parquet crate
lz4 = ["parquet2?/lz4_flex"]

all_compressions = ["brotli", "gzip", "snappy", "zstd", "lz4"]

# Full list of available features
full = [
"arrow",
"arrow2",
"console_error_panic_hook",
"parquet",
"parquet2",
"parquet/brotli",
"parquet/flate2",
# wasm-compatible lz4 not yet implemented
# "parquet/lz4",
"parquet/snap",
"parquet/zstd",
"parquet2/brotli",
"parquet2/gzip",
"parquet2/lz4_flex",
"parquet2/snappy",
"parquet2/zstd",
"reader",
"writer",
]
full = ["arrow1", "arrow2", "debug", "all_compressions", "reader", "writer"]

[dependencies]
wasm-bindgen = "0.2.80"
Expand Down
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ It's currently unknown how widespread the ecosystem support is for `LZ4_RAW`. As

In some cases, you may know ahead of time that your Parquet files will only include a single compression codec, say Snappy, or even no compression at all. In these cases, you may want to create a custom build of `parquet-wasm` to keep bundle size at a minimum. If you install the Rust toolchain and `wasm-pack` (see [Development](DEVELOP.md)), you can create a custom build with only the compression codecs you require.

Note that this project uses Cargo syntax newly released in version **1.60**. So you need version 1.60 or higher to compile this project. To upgrade your toolchain, use `rustup update stable`.

### Example custom builds

Reader-only bundle with Snappy compression using the `arrow` and `parquet` crates:

```
wasm-pack build --no-default-features --features arrow1 --features parquet/snap --features reader
wasm-pack build --no-default-features --features arrow1 --features snappy --features reader
```

Writer-only bundle with no compression support using the `arrow2` and `parquet2` crates, targeting Node:
Expand All @@ -153,38 +155,36 @@ wasm-pack build --target nodejs --no-default-features --features arrow2 --featur
Debug bundle with reader and writer support, targeting Node, using `arrow` and `parquet` crates with all their supported compressions, with `console_error_panic_hook` enabled:

```bash
wasm-pack build --dev --target nodejs \
--no-default-features --features arrow1 \
--features reader --features writer \
--features parquet_supported_compressions \
--features console_error_panic_hook
wasm-pack build \
--dev \
--target nodejs \
--no-default-features \
--features arrow1 \
--features reader \
--features writer \
--features all_compressions \
--features debug
# Or, given the fact that the default feature includes several of these features, a shorter version:
wasm-pack build --dev --target nodejs --features console_error_panic_hook
wasm-pack build --dev --target nodejs --features debug
```

Refer to the [`wasm-pack` documentation](https://rustwasm.github.io/docs/wasm-pack/commands/build.html) for more info on flags such as `--release`, `--dev`, `target`, and to the [Cargo documentation](https://doc.rust-lang.org/cargo/reference/features.html) for more info on how to use features.

### Available features

By default, `arrow`, `all_compressions`, `reader`, and `writer` features are enabled. Use `--no-default-features` to remove these defaults.

- `arrow1`: Use the `arrow` and `parquet` crates
- `arrow2`: Use the `arrow2` and `parquet2` crates
- `reader`: Activate read support.
- `writer`: Activate write support.
- `parquet_supported_compressions`: Activate all supported compressions for the `parquet` crate
- `parquet2_supported_compressions`: Activate all supported compressions for the `parquet2` crate
- parquet compression features. Should only be activated when `arrow1` is activated.
- `parquet/brotli`: Activate Brotli compression in the `parquet` crate.
- `parquet/flate2`: Activate Gzip compression in the `parquet` crate.
- `parquet/snap`: Activate Snappy compression in the `parquet` crate.
- ~~`parquet/lz4`~~: ~~Activate LZ4 compression in the `parquet` crate.~~ WASM-compatible version not yet implemented in the `parquet` crate.
- `parquet/zstd`: Activate ZSTD compression in the `parquet` crate.
- parquet2 compression features. Should only be activated when `arrow2` is activated.
- `parquet2/brotli`: Activate Brotli compression in the `parquet2` crate.
- `parquet2/gzip`: Activate Gzip compression in the `parquet2` crate.
- `parquet2/snappy`: Activate Snappy compression in the `parquet2` crate.
- `parquet2/lz4_flex`: Activate LZ4_RAW compression in the `parquet2` crate.
- `parquet2/zstd`: Activate ZSTD compression in the `parquet2` crate.
- `console_error_panic_hook`: Expose the `setPanicHook` function for better error messages for Rust panics.
- `all_compressions`: Activate all supported compressions for the crate(s) in use.
- `brotli`: Activate Brotli compression.
- `gzip`: Activate Gzip compression.
- `snappy`: Activate Snappy compression.
- `zstd`: Activate ZSTD compression.
- `lz4`: Activate LZ4_RAW compression (only applies to the `arrow2` endpoints).
- `debug`: Expose the `setPanicHook` function for better error messages for Rust panics. Additionally compiles CLI debug functions.

## Future work

Expand Down
7 changes: 4 additions & 3 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ wasm-pack build \
--features arrow2 \
--features reader \
--features writer \
--features parquet2_supported_compressions
--features all_compressions

# Build web version into tmp_build/esm2
echo "Building arrow2 esm"
Expand All @@ -60,7 +60,7 @@ wasm-pack build \
--features arrow2 \
--features reader \
--features writer \
--features parquet2_supported_compressions
--features all_compressions

# Build bundler version into tmp_build/bundler2
echo "Building arrow2 bundler"
Expand All @@ -73,7 +73,7 @@ wasm-pack build \
--features arrow2 \
--features reader \
--features writer \
--features parquet2_supported_compressions
--features all_compressions

# Copy files into pkg/
mkdir -p pkg/{node,esm,bundler}
Expand All @@ -87,6 +87,7 @@ cp tmp_build/bundler/{package.json,LICENSE_APACHE,LICENSE_MIT,README.md} pkg/
# Create minimal package.json in esm/ folder with type: module
echo '{"type": "module"}' > pkg/esm/package.json

# Create an esm2/ directory without import.meta.url in the JS ESM wrapper
cp -r pkg/esm pkg/esm2
sed '/import.meta.url/ s|input|// input|' pkg/esm2/arrow1.js > pkg/esm2/arrow1_new.js
sed '/import.meta.url/ s|input|// input|' pkg/esm2/arrow2.js > pkg/esm2/arrow2_new.js
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate web_sys;

#[cfg(feature = "arrow")]
#[cfg(feature = "arrow1")]
pub mod arrow1;

#[cfg(feature = "arrow2")]
Expand Down