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

Pass configuration flags to cargo #2899

Open
tschwinge opened this issue Mar 1, 2024 · 3 comments
Open

Pass configuration flags to cargo #2899

tschwinge opened this issue Mar 1, 2024 · 3 comments
Labels
misc upstream Issue regarding upstreaming gccrs into GCC

Comments

@tschwinge
Copy link
Member

As of #2822 "Start reusing rustc's format_args parser", we invoke cargo to produce object files to be linked into GCC. We currently don't specify any compilation flags and linker to use, so it's easy to run into mismatches between what GCC is configured for (for example, specific linker), and what cargo uses by default (for example, system cc for linking).

For example, the linker may be specified: https://doc.rust-lang.org/cargo/reference/config.html#targettriplelinker -- but do we need the Rust target triple for that (see #2898)? Trying to use a cfg() expressions à la --config "target.'cfg(all())'.linker=[...]" only produces:

warning: unused key `linker` in [target] config table `cfg(all())`

(Maybe I've misunderstood how that is to be used.)

@tschwinge
Copy link
Member Author

Next problem: the GCC $(LINKER) defaults to $(CXX), and doesn't just point to an executable, but may have "wrapper" executables prepended (ccache, for example), and also contain flags.

For a simple --config target.x86_64-unknown-linux-gnu.linker=\"'$(LINKER)'\", and LINKER = $(CXX), and CXX = ccache g++ [flags], we then get:

error: linker `[...]/build-gcc/gcc/ccache g++ [flags] ` not found

@CohenArthur
Copy link
Member

oh, that's really sad... any chance there's another make variable you haven't thought about which is just the linker binary and not the full invocation? it seems this is the offending line in my generated Makefile, which seems wrong (why not add it to LINKER_FLAGS?) but maybe I'm not thinking of something.

# Link with -no-pie since we compile the compiler with -fno-PIE.
LINKER += $(NO_PIE_FLAG)

@powerboat9
Copy link
Contributor

powerboat9 commented Mar 5, 2024

It looks like target.<triple>.rustflags and link-args could be used to pass arguments to the linker. We could split $(LINKER) into an executable and argument list if need be.

@CohenArthur CohenArthur added the upstream Issue regarding upstreaming gccrs into GCC label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
misc upstream Issue regarding upstreaming gccrs into GCC
Projects
None yet
Development

No branches or pull requests

3 participants