project ( 'static rust and c polyglot executable' , 'c' , 'rust' )
Implement rustc controlled whole-archive linking
Rustc as of version 1.61.0 has support for controlling when
whole-archive linking takes place, previous to this it tried to make a
good guess about what you wanted, which worked most of the time. This is
now implemented.
Additionally, rustc makes some assumptions about library names
(specifically static names), that meson does not keep. This can be fixed
with rustc 1.67, where a new +verbatim modifier has been added. We can
then force rustc to use the name we give it. Before that, we can sneak
through `/WHOELARCHIVE:` in cases of dynamic linking (into a dll or
exe), but we can't force the archiver to do what we want (rustc
considers the archiver to be an implementation detail). The only
solution I can come up with is to copy the library to the format that
rustc expects. I've run into some issues with that as well, so we warn
in that case.
The decisions to leave static into static broken on MSVC for 1.61–1.66
was made because:
1) The work around is non-trivial, and we would have to support that
workaround for a long time
2) The number of users of Rust in Meson is small
3) The number of users of Rust in Meson on Windows, with MSVC is tiny
4) Using rustup to update rustc on windows is trivial, and solves the
problem completely
Fixes: #10723
Fixes: #11247
Co-authored-by: Nirbheek Chauhan <nirbheek@centricular.com>
2 years ago
r = static_library ( 'stuff' , 'stuff.rs' , rust_crate_type : 'staticlib' )
# clib is installed static library and stuff is not installed. That means that
# to be usable clib must link_whole stuff. Meson automatically promote to link_whole,
# as it would do with C libraries, but then cannot extract objects from stuff and
# thus should error out.
# FIXME: We should support this use-case in the future.
testcase expect_error ( 'Cannot link_whole a custom or Rust target \'stuff\' into a static library \'clib\'. Instead, pass individual object files with the "objects:" keyword argument if possible. Meson had to promote link to link_whole because \'clib\' is installed but not \'stuff\', and thus has to include objects from \'stuff\' to be usable.' )
l = static_library ( 'clib' , 'clib.c' , link_with : r , install : true )
endtestcase
l = static_library ( 'clib' , 'clib.c' , link_with : r )
e = executable ( 'prog' , 'prog.c' ,
link_with : l ,
install : true )
test ( 'polyglottest' , e )
# Create a version that has overflow-checks on, then run a test to ensure that
# the overflow-checks is larger than the other version by some ammount
r2 = static_library ( 'stuff2' , 'stuff.rs' , rust_crate_type : 'staticlib' , rust_args : [ '-C' , 'overflow-checks=on' ] )
l2 = static_library ( 'clib2' , 'clib.c' )
e2 = executable ( 'prog2' , 'prog.c' , link_with : [ r2 , l2 ] )
test ( 'overflow-checks' , find_program ( 'overflow_size_checks.py' ) , args : [ e , e2 ] )