#moving RUSTFLAGS to .cargo/config.toml

49 messages · Page 1 of 1 (latest)

rotund birch
#

I want to move these to a config, but when I do it they either apply to everything or nothing. It's in a workspace, and only for the target x86_64-polished-kernel.json . Right now, i have:

RUSTFLAGS="-C relocation-model=static -C link-args=-no-pie -C link-arg=-Tkernel/linker.ld" cargo build -p kernel -Zbuild-std=core,alloc --target x86_64-polished-kernel.json
#

usually i can do it but ive never applied it to a workspace member specifically

wraith rain
#

You don't. You apply it to a target.

[target.'cfg(...)']
rustflags = [...]
rotund birch
#

i tried that but didn't put cfg

wraith rain
#

in .cargo/config.toml

rotund birch
#
[target.'cfg(x86_64-polished-kernel.json)']

?

rotund birch
wraith rain
rotund birch
#

huh

#

i don't think i have a cfg flag i could use just for the kernel member?

#

~/workspace/.cargo/config.toml though right

wraith rain
rotund birch
#

"vendor": "unknown",

wraith rain
#

well, set it to something unique

rotund birch
#

Okay

wraith rain
#

cargo's configuration file has nothing to do with the workspace

rotund birch
#
[target.'cfg(target_vendor = "polished")']
rustflags = [
    "-C", "link-arg=-Tkernel/linker.ld",
]

?

wraith rain
#

it is configuration for the cargo tool itself, not any particular project. the .cargo directory that contains it can be located in ., .., ../.., etc.

#

or, even if it is not a parent, ~/

rotund birch
#

bruh

#

im used to one per rust project

#

i just need it to apply the linker.ld for one workspace member 😭

wraith rain
#

that is certainly one way to configure cargo

wraith rain
#

assuming that is set in the spec json passed to rustc, yes

#

a linker flag for a particular bin or cdylib artifact is generally set from the build script

rotund birch
#

i think it is?

rotund birch
wraith rain
#
fn main() {
    println!("cargo::rustc-link-arg=-Tkernel/linker.ld")
}
#

if you did not try this before resorting to RUSTFLAGS, I recommend trying it, though it is possible that the linker script flag in particular does not work

rotund birch
#

hm

rotund birch
rotund birch
#

why is it println and not some other method that would make more sense

rotund birch
#

weird

#

i feel like its against rust to do magic shit with printlns when building but ig not in this one case

wraith rain
rotund birch
#

so this adds a build directive?

rotund birch
#

Build scripts communicate with Cargo by printing to stdout. Cargo will interpret each line that starts with cargo:: as an instruction that will influence compilation of the package. All other lines are ignored.

#

Ah

#

interesting

#

well thanks

rotund birch
wraith rain
#

no, build.rs can't set rustc flags besides -L

#

and those codegen args have unfortunately not been ported to profile options. so those must remain in custom rustc flags.

#

though they are probably universal to all instances of cfg(target_os = "none")