Open jameshilliard opened 3 years ago
I'm attempting to use this to fix https://github.com/rust-lang/docs.rs/issues/1580 by setting the configured rustc-args
for all the target and host builds, using this command I expected to see the --cfg procmacro2_semver_exempt
make it through to the build_script_build
rustc invocation, but it doesn't appear to, am I misunderstanding this feature or is something going wrong here?
cargo rustdoc -vv \
--target x86_64-unknown-linux-gnu \
--config 'build.rustflags=["--cfg", "procmacro2_semver_exempt"]' \
--config 'host.rustflags=["--cfg", "procmacro2_semver_exempt"]' \
-Zhost-config -Ztarget-applies-to-host -Zunstable-options \
-- --cfg procmacro2_semver_exempt --cfg doc_cfg
It looks like rustflags are still being explicitly excluded from all build-scripts, it seems like this feature should change this to read from the host.rustflags
(and target specific subtables):
I'm currently unsure if the unstable host-config
implementation is expected to Just Work with cargo clippy
but I'm finding that I need to use -Zhost-config
, which works with cargo build
but doesn't seem to work with cargo clippy
currently.
In this project we have certain crates that are considered "modules" which may either be cross compiled as wasm32-unknown-unknown
modules and loaded at runtime, or else with --cfg=native_modules
they may be compiled natively and directly linked into the runtime.
This --cfg=native_modules
option affects multiple crates that form part of a runtime and it also needs to affect our proc macros which generate an FFI interface for our modules.
We can't practically use cargo features for this, while native linking is mutually exclusive with wasm linking and although we can define a precedence for cfg()
guards in rust code, we also need to be able to resolve the mutual exclusion when deciding dependencies too.
It's also notable that this project's runtime runs on PC and mobile and in particular we want this native_module
linking on iOS where we can't avoid using --target
.
It would be good to understand if it's just a short-term limitation of the host-config
implementation that it's not handled consistently by cargo clippy
(not sure about other cargo subcommands besides build
currently) or would it make sense to open some other issue to discuss having cargo clippy
also support this?
Summary
Original issue: #3349 Implementation: #9322 Documentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#host-config Issues: https://github.com/rust-lang/cargo/labels/Z-host-config
The
host
key in a config file can be used pass flags to host build targets such as build scripts that must run on the host system instead of the target system when cross compiling. It supports both generic and host arch specific tables. Matching host arch tables take precedence over generic host tables.