In NativeAOT in .NET 8 or later, we need to link libbootstrapperdll.o
/bootstrapperdll.obj
to final executable to initialize NativeAOT.
(this code is compiled to libbootstrapperdll.o
and distributed as a part of NativeAOT runtime.)
I'm making rlib library crate with NativeATO staticlib so I have to ask cargo to link libbootstrapperdll.o
for final binary linker.
What's the best way to link some object file for executable file?
What I tried
- I added
println!("cargo:rustc-link-arg={bootstrapper}");
tobuild.rs
of the rlib crate. but it does not addbootstrapperdll.o
for linking executable. - I craeated
libbootstrapper.a
which containslibbootstrapper.o
and addedprintln!("cargo:rustc-link-lib=static=bootstrapperdll");
tobuild.rs
of the rlib crate.- This adds
libbootstrapper.o
to the rlib file but the linker does include nothing fromlibbootstrapper.o
since any symbols inlibbootstrapper.o
is referenced from nowhere.
- This adds
What I know
- I know full path to
libbootstrapperdll.o
inbuild.rs
of rlib crate. - I have full control of
build.rs
of bin crate for my usage so I can add some code in bin crate. (However,build.rs
of bin crate does not know wherebootstrapperdll.o
is at.)