gba icon indicating copy to clipboard operation
gba copied to clipboard

Move link args from .cargo/config to build.rs

Open crawfxrd opened this issue 4 years ago • 6 comments

Move the linker option from .cargo/config.toml to build.rs using the rustc-link-arg-bins directive.

Then users only needs to specific extra-link-arg to rustc, instead of copying the files from this repo to their project.

Ref: https://github.com/rust-lang/cargo/pull/7811 Ref: https://github.com/crawfxrd/gba-dev-rs/commit/db5d897aa8ec23229db6c933bb16fec221b2d199

crawfxrd avatar Apr 30 '21 22:04 crawfxrd

iiiinteresting.

Yeah this sounds like it could be good. does it let a lib crate pass a linker script "downstream" to a binary using the lib?

Lokathor avatar Apr 30 '21 22:04 Lokathor

I believe so. I've converted my GBA-specific code to a local crate, and the only change I had to make from the commit I linked was to specific CARGO_MANIFEST_DIR for the full linker file path (build.rs).

crawfxrd avatar Apr 30 '21 22:04 crawfxrd

How would this work with downstream crates that have their own build requirements? I wouldn't want any of the gba crate's default linker settings, as I'm writing a patch that gets integrated into an existing ROM as part of a ROM hack -- something that obviously requires a very different linker script compared to normal.

This should be doable with a default feature flag you can turn off or something, I suppose?

Lymia avatar May 02 '21 00:05 Lymia

That's a good point.

It would have to be feature flag controlled or something like that.

Also, I think that I'll wait on this change until after cargo stabilizes it (https://github.com/rust-lang/cargo/issues/9426)

Lokathor avatar May 02 '21 01:05 Lokathor

rustc-link-arg was stabilized (rust-lang/cargo#9557).

However, they decided that transitive link arguments are bad and you must always explicitly opt-in for custom link arguments (rust-lang/cargo#9554).

So every binary must still copy the linker script and build.rs/.cargo/config.

crawfxrd avatar Jul 27 '21 22:07 crawfxrd

"oh good"

Lokathor avatar Jul 28 '21 00:07 Lokathor

Since every binary has to copy the config anyway, i think we will skip this change.

Lokathor avatar Oct 06 '22 18:10 Lokathor