rust-lang / rust-lang/cargo

There is no way to set RUSTFLAGS for build scripts (or proc macros) when cross-compiling

Open
#4,423 40 comments 34 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-build-scripts A-cross-compiling A-rustflags C-enhancement S-needs-design
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

The cargo documentation environment-variables.md says

RUSTFLAGS - A space-separated list of custom flags to pass to all compiler invocations that Cargo performs. In contrast with cargo rustc, this is useful for passing a flag to all compiler instances.

This is wrong, unfortunately. The flag is not passed to all compiler instances: When cross-compiling (i.e., when --target is set), the flag is not passed to build scripts. It seems there is currently no way to pass anything to build scripts when --target is set, which clearly is a feature gap. Cargo should provide a way to set flags for build scripts even when cross-compiling.

One may be tempted to set CARGO_TARGET_<target>_RUSTFLAGS or target.<target>.rustflags, but that does not work either.

Also see https://github.com/rust-lang/cargo/issues/9453, https://github.com/rust-lang/cargo/issues/9452.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Cargo documentation in environment-variables.md and the behavior of RUSTFLAGS when --target is set. Compare the reported handling of build scripts and proc macros with the related issues #9453 and #9452. Done means Cargo provides a documented way to pass the intended flags during cross-compilation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.