Skip to content

-Zhost-config doesn't apply host.rustflags to build-script-builds #10206

Closed
@Nemo157

Description

Problem

When using -Zhost-config to add in rustflags to apply to the host-only builds, these are still not passed to rustc when building build-scripts.

Steps

> cargo new foo && cd foo
     Created binary (application) `foo` package
> echo 'fn main() { assert!(cfg!(foo)); }' > build.rs
> cargo build -Zhost-config -Ztarget-applies-to-host -Zunstable-options --config 'host.rustflags=["--cfg=foo"]'
   Compiling foo v0.1.0 (/tmp/tmp.9cICAJ9mce/foo)
error: failed to run custom build command for `foo v0.1.0 (/tmp/tmp.9cICAJ9mce/foo)`

Caused by:
  process didn't exit successfully: `/home/nemo157/.cargo/shared-target/debug/build/foo-ba25a7af077036f3/build-script-build` (exit status: 101)
  --- stderr
  thread 'main' panicked at 'assertion failed: cfg!(foo)', build.rs:1:13
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Possible Solution(s)

I believe the issue is around here, this should be still applying the host rustflags to the build-script builds

if requested_kinds != [CompileKind::Host] && kind.is_host() {
// This is probably a build script or plugin and we're
// compiling with --target. In this scenario there are
// no rustflags we can apply.
return Ok(Vec::new());
}

Notes

Originally mentioned on the tracking issue; but after more thought I'm fairly confident this is a bug.

Version

cargo 1.59.0-nightly (a359ce160 2021-12-14)
release: 1.59.0-nightly
commit-hash: a359ce16073401f28b84840da85b268aa3d37c88
commit-date: 2021-12-14
host: x86_64-unknown-linux-gnu
libgit2: 1.3.0 (sys:0.13.23 vendored)
libcurl: 7.80.0-DEV (sys:0.4.51+curl-7.80.0 vendored ssl:OpenSSL/1.1.1l)
os: Arch Linux [64-bit]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions