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

the .cargo/config.toml rustflags did not passed to the compiler #12794

Closed
jiangxiaoqiang opened this issue Oct 8, 2023 · 5 comments
Closed
Labels
C-bug Category: bug S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.

Comments

@jiangxiaoqiang
Copy link

jiangxiaoqiang commented Oct 8, 2023

When I migrate the rustflags from command line to config files, the rustflags did not passed to the compiler. I am compile the project with FFI using command like this:

RUSTFLAGS='-L ./src/so' cargo build

it works fine. but when I changed to the config file:

[build]
rustflags = ["-L", "/Users/xiaoqiangjiang/source/reddwarf/backend/rust-learn/src/so"]

could not compile the project.

I tried this code:

[build]
rustflags = ["-L", "/Users/xiaoqiangjiang/source/reddwarf/backend/rust-learn/src/so"]

I expected to see this happen:

both using command and config could compile the project success.

Instead, this happened:

command line works, config file failed.

Meta

rustc --version --verbose:

> rustc --version --verbose
rustc 1.72.1 (d5c2e9c34 2023-09-13)
binary: rustc
commit-hash: d5c2e9c342b358556da91d61ed4133f6f50fc0c3
commit-date: 2023-09-13
host: aarch64-apple-darwin
release: 1.72.1
LLVM version: 16.0.5

the minimal reproduce example:

git clone -b rustflags https://github.com/jiangxiaoqiang/rust-learn.git

there is the similiar issue told that maybe rustc issue: #4452

@jiangxiaoqiang jiangxiaoqiang added the C-bug Category: bug label Oct 8, 2023
@weihanglo weihanglo transferred this issue from rust-lang/rust Oct 8, 2023
@weihanglo
Copy link
Member

Could you run cargo build --verbose and check if there is -L /Users/xiaoqiangjiang/source/reddwarf/backend/rust-learn/src/so being passed?

Also, there are a list of precedence of how Cargo picks rustflags config. Please see the order and check if your build.rustflags was overriden by other configs.

@weihanglo weihanglo added the S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. label Oct 8, 2023
@jiangxiaoqiang
Copy link
Author

Could you run cargo build --verbose and check if there is -L /Users/xiaoqiangjiang/source/reddwarf/backend/rust-learn/src/so being passed?

Also, there are a list of precedence of how Cargo picks rustflags config. Please see the order and check if your build.rustflags was overriden by other configs.

I have checked, there is no -L /Users/xiaoqiangjiang/source/reddwarf/backend/rust-learn/src/so passed. I have checked the order and there is no config overriden the rustflags from file. Actually I found many places mention this issue, it looks like a bug.

@weihanglo
Copy link
Member

Thanks for the reply. I can reproduce it with provided repo and found there is -L /Users/xiaoqingjiang/... in every rustc invocation.

Could you check if CARGO_ENCODED_RUSTFLAGS or RUSTFLAGS were passed as an empty string? Any empty string of them would also take precedence over build.rustflags config value.

I would also suggest using cargo +nightly -Z unstable-options config get --show-origin and check the config values. If possible, please remove sensitive data and share the output.

I found many places mention this issue, it looks like a bug.

Could you point them out? At this moment with limited info, I cannot see any issue related to this one, except #12087 which talks about bad discovery of rustflags override chain.

@jiangxiaoqiang
Copy link
Author

wired. I am check the "-L", "/Users/xiaoqiangjiang/source/reddwarf/backend/rust-learn/src/so" in the build.log file generate by command:

cargo build --verbose &> build.log

there is no path /Users/xiaoqiangjiang/source/reddwarf/backend/rust-learn/src/so with L parameter. Am I doing this the right way? this is the config:

> cargo +nightly -Z unstable-options config get --show-origin
alias.b = "build" # /Users/xiaoqiangjiang/source/reddwarf/backend/texhub-server/.cargo/config.toml
build.rustflags = [
    "-L", # /Users/xiaoqiangjiang/source/reddwarf/backend/texhub-server/.cargo/config.toml
    "/Users/xiaoqiangjiang/source/reddwarf/backend/texhub-server/src/so", # /Users/xiaoqiangjiang/source/reddwarf/backend/texhub-server/.cargo/config.toml
]
source.crates-io.registry = "https://github.com/rust-lang/crates.io-index" # /Users/xiaoqiangjiang/.cargo/config
source.crates-io.replace-with = "tuna" # /Users/xiaoqiangjiang/.cargo/config
source.rustcc.registry = "git://crates.rustcc.cn/crates.io-index" # /Users/xiaoqiangjiang/.cargo/config
source.sjtu.registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index" # /Users/xiaoqiangjiang/.cargo/config
source.tuna.registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git" # /Users/xiaoqiangjiang/.cargo/config
source.ustc.registry = "git://mirrors.ustc.edu.cn/crates.io-index" # /Users/xiaoqiangjiang/.cargo/config
# The following environment variables may affect the loaded values.
# CARGO_HOME=/Users/xiaoqiangjiang/.cargo

from the config it look like the config make effect but I could not build the project using cargo build, thow the error:

"/Users/xiaoqiangjiang/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-49cb3ef59194e1e6.rlib" "/Users/xiaoqiangjiang/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-40415e957020687a.rlib" "-framework" "Security" "-framework" "Security" "-lpq" "-framework" "CoreFoundation" "-lssl" "-lcrypto" "-liconv" "-lSystem" "-lc" "-lm" "-L" "/Users/xiaoqiangjiang/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/Users/xiaoqiangjiang/source/reddwarf/backend/texhub-server/target/debug/deps/texhub_server-c2cd989f5bc32ef7" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: ld: warning: directory not found for option '-L/System/Volumes/Data/opt/homebrew/Cellar/libpq/15.2/lib'
          ld: library not found for -lsynctex_parser
          clang: error: linker command failed with exit code 1 (use -v to see invocation)


@jiangxiaoqiang
Copy link
Author

sorry my mistake, it seems the env RUSTFLAGS config override the rustflags. I found the config:

> env|grep "RUSTFLAGS"
RUSTFLAGS=-L /System/Volumes/Data/opt/homebrew/Cellar/libpq/15.2/lib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.
Projects
None yet
Development

No branches or pull requests

2 participants