Rustc-link-search in cargo config

I am trying to setup my system for cross-compiling by using the cargo config file. This way, for a given target, the linker, ar, and library path info can be setup by default and I don't have to set it up per project.

To be more concrete, I have my config file at ~/.cargo/config.toml and its contents are:

[target.aarch64-linux-android]
ar = "/path/to/aarch64/ar"
linker = "/path/to/aarch64/ld"
rustc-link-search = { all = "/path/to/aarch64/libs" }

This works well for specifying the archiver and linker, but I can't figure how to get rustc-link-search to work. An example of how to use it can be seen here, but the documentation is wrong. It shows that a list of paths can be passed, but when I try that cargo/rust tells me that it is expecting a table, but got an array.

Ok, so it wants map. I assume the keys are one of the KINDs listed here, but I'm not really sure. In any case, it doesn't seem to add the directory to the library search path.

Can anyone shed some light on how to correctly use the rustc-link-search configuration field?

It seems that the documentation is also wrong for rustc-flags. It shows the argument takes a string, but it also seems to want a table. No clue how the keys/values should work on that one either.

If a manifest contains a links key, then Cargo supports overriding the build script specified with a custom library. The purpose of this functionality is to prevent running the build script in question altogether and instead supply the metadata ahead of time.

This functionality is only for overriding build scripts. It doesn't work when there is no build script. Try

[target.aarch64-linux-android]
ar = "/path/to/aarch64/ar"
linker = "/path/to/aarch64/ld"
rustflags = ["-L", "/path/to/aarch64/libs"]

instead. This will pass -L /path/to/aarch64/libs to all rustc invocations.

Ok, I didn't realize it was only for overriding build script. I tried the 'rustflags' keyword, and it doesn't seem to pass the arguments to the linker.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.