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

CARGO_CFG_TARGET_FAMILY is not defined for build-script in no_std #12728

Closed
lukaslueg opened this issue Sep 24, 2023 · 3 comments · Fixed by #13069
Closed

CARGO_CFG_TARGET_FAMILY is not defined for build-script in no_std #12728

lukaslueg opened this issue Sep 24, 2023 · 3 comments · Fixed by #13069
Labels
A-build-scripts Area: build.rs scripts A-documenting-cargo-itself Area: Cargo's documentation C-bug Category: bug S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@lukaslueg
Copy link
Contributor

lukaslueg commented Sep 24, 2023

Problem

There is an issue reported downstream where the CARGO_CFG_TARGET_FAMILY environment variable is not defined when executing a build-script for a no_std binary. The said environment variable seems to be indeed not defined at all. AFAICS this is contrary to what is documented about the environment variables set by cargo, e.g. here or here.

Steps

  • Set main.rs to be [no_std]
  • Add a build.rs
  • Try to observe CARGO_CFG_TARGET_FAMILY in build.rs while building the no_std-binary.
  • While most variables are defined as documented, CARGO_CFG_TARGET_FAMILY is not present in the build-script's environment.

Possible Solution(s)

The way I read the documentation, the listed environment variables (including CARGO_CFG_TARGET_FAMILY, even in a no_std setting) should always be defined. If they have no value, possibly because they have no meaning in the given setting, they could be set to the empty string / NULL. The exact behavior of subprocesses launched by a build-script (if any) seems to vary with respect to empty environment variables, though.

If the full set of environment variables mentioned in the documentation can't be made present in all settings, this should be documented.

Notes

Notice that CARGO_CFG_TARGET_OS: none is defined in the downstream bug report, while CARGO_CFG_TARGET_FAMILY is not.

Version

cargo 1.72.0 (103a7ff2e 2023-08-15)
release: 1.72.0
commit-hash: 103a7ff2ee7678d34f34d778614c5eb2525ae9de
commit-date: 2023-08-15
host: x86_64-apple-darwin
libgit2: 1.6.4 (sys:0.17.2 vendored)
libcurl: 8.1.2 (sys:0.4.63+curl-8.1.2 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1u  30 May 2023
os: Mac OS 13.5.2 [64-bit]
@lukaslueg lukaslueg added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Sep 24, 2023
@epage epage added the A-build-scripts Area: build.rs scripts label Sep 25, 2023
@epage
Copy link
Contributor

epage commented Sep 25, 2023

Looking at the code, it seems we are generically processing whatever rustc gives us with the only special case being debug_assertions.

@cavivie
Copy link

cavivie commented Oct 18, 2023

I had a similar issue happening with the cross-rs i686_pc_windows_msvc target, where cross was not passing CARGO_CFG_TARGET_FAMILY to the docker runner container launched by cross-rs docker. plz note that cross-rs uses xargo to build the target i686_pc_windows_msvc.

@ehuss ehuss added A-documenting-cargo-itself Area: Cargo's documentation S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-triage Status: This issue is waiting on initial triage. labels Nov 22, 2023
@ehuss
Copy link
Contributor

ehuss commented Nov 22, 2023

I'm marking this as a documentation issue. Some targets just don't have families, in which case it won't be set. The documentation at /~https://github.com/rust-lang/cargo/blob/master/src/doc/src/reference/environment-variables.md#environment-variables-cargo-sets-for-build-scripts could be a little more clear to explicitly mention that some variables won't be set if the target does not have the corresponding setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-scripts Area: build.rs scripts A-documenting-cargo-itself Area: Cargo's documentation C-bug Category: bug S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants