Skip to content
This repository has been archived by the owner on Jun 15, 2020. It is now read-only.

Commit

Permalink
chore(cargo) Create 2 Cargo.toml file: One for stable, one for nigh…
Browse files Browse the repository at this point in the history
…tly.

`rustc` nightly is required for `no_std`, which is required only for
the WASM target. nom needs to be used with the feature `alloc` in this
particular case. So to get stable for every other targets, we should
write:

```toml
[target.'cfg(feature = "wasm")'.dependencies]
nom = { version = "4.0.0", default-features = false, features = ["alloc"] }

[target.'cfg(not(feature = "wasm"))'.dependencies]
nom = { version = "4.0.0" }
```

Sadly, it does not work, see rust-lang/cargo#2524.

The only alternative I found so far, is to use 2 `Cargo.toml`
files. Next commits are likely to split the repository into Cargo
workspaces.
  • Loading branch information
Hywan committed Jun 22, 2018
1 parent a07dc8d commit d0a7650
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target-dir = "./target"
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/Cargo.lock
Cargo.lock
/bindings/asmjs/gutenberg_post_parser.asm.js
/bindings/asmjs/gutenberg_post_parser.asm.js.br
/bindings/asmjs/gutenberg_post_parser.asm.js.gz
/bindings/c/gutenberg-post-parser
/bindings/c/gutenberg_post_parser.h
/bindings/nodejs/native/Cargo.lock
/bindings/nodejs/native/artifacts.json
/bindings/nodejs/native/index.node
/bindings/nodejs/native/target/
Expand Down
43 changes: 43 additions & 0 deletions cargo/no_std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "gutenberg_post_parser"
version = "0.10.0"
authors = ["Ivan Enderlin <ivan.enderlin@hoa-project.net>"]
license = "BSD-3-Clause"
readme = "../../README.md"
repository = "https://github.com/Hywan/gutenberg-parser-rs"
build = "../../build.rs"

[[bin]]
name = "gutenberg-post-parser"
path = "../../src/main.rs"
required-features = ["bin"]

[lib]
name = "gutenberg_post_parser"
crate-type = ["cdylib", "dylib", "lib", "staticlib"]
path = "../../src/lib.rs"

[profile.release]
debug = false
lto = true
opt-level = 3

[features]
default = ["nodejs"] # Because of a strange behavior, `nodejs` must be in `default`. Use `just --list` to compile correctly.
wasm = ["wee_alloc"]
c = ["cbindgen"]
nodejs = ["neon", "neon-build", "serde_json", "neon-serde"]
bin = ["failure", "clap"]

[dependencies]
nom = { version = "4.0.0", default-features = false, features = ["alloc"] }
wee_alloc = { version = "0.4.1", optional = true }
neon = { version = "0.1.23", optional = true }
serde_json = { version = "1.0.21", optional = true }
neon-serde = { version = "0.0.3", optional = true }
failure = { version = "0.1.1", optional = true }
clap = { version = "^2.31.2", optional = true }

[build-dependencies]
cbindgen = { version = "0.6.0", optional = true }
neon-build = { version = "0.1.23", optional = true }
43 changes: 43 additions & 0 deletions cargo/std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "gutenberg_post_parser"
version = "0.10.0"
authors = ["Ivan Enderlin <ivan.enderlin@hoa-project.net>"]
license = "BSD-3-Clause"
readme = "../../README.md"
repository = "https://github.com/Hywan/gutenberg-parser-rs"
build = "../../build.rs"

[[bin]]
name = "gutenberg-post-parser"
path = "../../src/main.rs"
required-features = ["bin"]

[lib]
name = "gutenberg_post_parser"
crate-type = ["cdylib", "dylib", "lib", "staticlib"]
path = "../../src/lib.rs"

[profile.release]
debug = false
lto = true
opt-level = 3

[features]
default = ["nodejs"] # Because of a strange behavior, `nodejs` must be in `default`. Use `just --list` to compile correctly.
wasm = ["wee_alloc"]
c = ["cbindgen"]
nodejs = ["neon", "neon-build", "serde_json", "neon-serde"]
bin = ["failure", "clap"]

[dependencies]
nom = { version = "4.0.0" }
wee_alloc = { version = "0.4.1", optional = true }
neon = { version = "0.1.23", optional = true }
serde_json = { version = "1.0.21", optional = true }
neon-serde = { version = "0.0.3", optional = true }
failure = { version = "0.1.1", optional = true }
clap = { version = "^2.31.2", optional = true }

[build-dependencies]
cbindgen = { version = "0.6.0", optional = true }
neon-build = { version = "0.1.23", optional = true }
1 change: 1 addition & 0 deletions cargo/std/tests
22 changes: 12 additions & 10 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cwd = `pwd`
cargo_no_std = "cargo/no_std/Cargo.toml"
cargo_std = "cargo/std/Cargo.toml"
asmjs_directory = "bindings/asmjs"
c_directory = "bindings/c"
nodejs_directory = "bindings/nodejs"
Expand All @@ -7,15 +9,15 @@ wasm_directory = "bindings/wasm"

# Build a regular library..
build-library:
cargo build --no-default-features --release
cargo build --manifest-path {{cargo_std}} --no-default-features --release

# Build a regular binary.
build-binary:
cargo build --no-default-features --features "bin" --release
cargo build --manifest-path {{cargo_std}} --no-default-features --features "bin" --release

# Build the parser and produce a WASM binary.
build-wasm:
RUSTFLAGS='-g' cargo +nightly build --no-default-features --features "wasm" --target wasm32-unknown-unknown --release
RUSTFLAGS='-g' cargo +nightly build --manifest-path {{cargo_no_std}} --no-default-features --features "wasm" --target wasm32-unknown-unknown --release
cp target/wasm32-unknown-unknown/release/gutenberg_post_parser.wasm {{wasm_directory}}
cd {{wasm_directory}} && \
wasm-gc gutenberg_post_parser.wasm && \
Expand Down Expand Up @@ -45,7 +47,7 @@ build-asmjs: build-wasm

# Build the parser and produce a C binary.
build-c:
cargo build --no-default-features --features "c" --release
cargo build --manifest-path {{cargo_std}} --no-default-features --features "c" --release
cd {{c_directory}} && \
clang \
-Wall \
Expand All @@ -60,11 +62,11 @@ build-c:

# Build the parser and produce a NodeJS native module.
build-nodejs:
RUSTFLAGS='--cfg feature="nodejs"' neon build --debug --rust nightly --path {{nodejs_directory}}/
RUSTFLAGS='--cfg feature="nodejs"' neon build --debug --path {{nodejs_directory}}/

# Build the parser and produce a PHP extension.
build-php:
cargo build --no-default-features --features "c" --release
cargo build --manifest-path {{cargo_std}} --no-default-features --features "c" --release
cd {{php_directory}}/extension/gutenberg_post_parser/ && \
phpize && \
./configure && \
Expand All @@ -75,19 +77,19 @@ test: test-library-unit test-library-integration test-documentation

# Run the unit tests.
test-library-unit:
cargo test --lib --no-default-features
cargo test --manifest-path {{cargo_std}} --lib --no-default-features

# Run the integration tests.
test-library-integration:
cargo test --test integration --no-default-features
cargo test --manifest-path {{cargo_std}} --test integration --no-default-features

# Run the documentation tests.
test-documentation:
cargo test --doc --no-default-features
cargo test --manifest-path {{cargo_std}} --doc --no-default-features

# Build the documentation.
build-doc:
cargo doc --release --no-default-features --package gutenberg_post_parser
cargo doc --manifest-path {{cargo_std}} --release --no-default-features --package gutenberg_post_parser

# Open the documentation.
open-doc: build-doc
Expand Down
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

0 comments on commit d0a7650

Please sign in to comment.