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

corrosion_add_cxxbridge does not respect crate features #597

Open
FabianHummel opened this issue Jan 1, 2025 · 1 comment · May be fixed by #598
Open

corrosion_add_cxxbridge does not respect crate features #597

FabianHummel opened this issue Jan 1, 2025 · 1 comment · May be fixed by #598

Comments

@FabianHummel
Copy link

corrosion_import_crate(
        MANIFEST_PATH example_path/Cargo.toml
        FEATURES interop) # Note this feature flag here
        
corrosion_add_cxxbridge(example-bridge
        CRATE example
        MANIFEST_PATH example_path
        FILES ffi.rs)
[package]
name = "example"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]

[features]
interop = ["dep:cxx", "dep:cxx-build"] # We lock cxx features behind this feature flag.

[dependencies]
cxx = { version = "1.0.135", optional = true }

[build-dependencies]
cxx-build = { version = "1.0.135", optional = true }

https://github.com/corrosion-rs/corrosion/blob/999f93b98e965dc418b43854ad321a4e45385983/cmake/Corrosion.cmake#L1674C1-L1680C6

The command that is run in the code linked above (/Users/.../.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo tree -i cxx --depth=0) returns the error described below, because cxx is locked behind the interop feature flag.

error: package ID specification 'cxx' did not match any packages

	Did you mean 'syn'?

It can be fixed by adding the features that are passed to corrosion_import_crate to the cargo tree command, so it looks like this: /Users/.../.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo tree -i cxx --features interop --depth=0 which then returns the correct cxx version: cxx v1.0.135

Why lock cxx behind a feature flag?

My crate is being cross-compiled to many different platforms and contains lots of shared code for either WebAssembly (wasm-bindgen) and C++ (cxx) which needs to be toggled based on where it's built.

@FabianHummel FabianHummel linked a pull request Jan 1, 2025 that will close this issue
@jschwe
Copy link
Collaborator

jschwe commented Jan 3, 2025

My crate is being cross-compiled to many different platforms and contains lots of shared code for either WebAssembly (wasm-bindgen) and C++ (cxx) which needs to be toggled based on where it's built.

The same use case could also be solved by dependencies conditional per target-triple, so I guess we should also respect the target / or pass --target all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants