Skip to content

Rust static linking with +verbatim= fails on macosΒ #15020

@elmarco

Description

@elmarco

Describe the bug
Modified test 3 fails to link:

[1/1] Compiling Rust source '../test cases/rust/3 staticlib/prog.rs'
FAILED: [code=1] prog 
rustc -C linker=cc --color=always -C debug-assertions=yes -C overflow-checks=no --crate-type bin -g --crate-name prog --emit dep-info=prog.p/prog.d --emit link=prog -C metadata=prog@exe --extern stuff=libstuff.rlib -Clink-arg=libvalue.a -L. '../test cases/rust/3 staticlib/prog.rs'
error: linking with `cc` failed: exit status: 1
  |
  = note:  "cc" "/var/folders/1l/gdhl58ps3x9g3722b48txl0w0000gn/T/rustcxctcQc/symbols.o" "<2 object files omitted>" "/Users/user/meson/builddir/{libstuff.rlib}.rlib" "-llibvalue.a" "./{libother.rlib}.rlib" "-llibvalue.a" "<sysroot>/lib/rustlib/x86_64-apple-darwin/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-lSystem" "-lc" "-lm" "-arch" "x86_64" "-mmacosx-version-min=10.12.0" "-L" "." "-o" "prog" "-Wl,-dead_strip" "-nodefaultlibs" "libvalue.a"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: ld: warning: ignoring duplicate libraries: '-llibvalue.a', 'libvalue.a'
          ld: library 'libvalue.a' not found
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

To Reproduce
Change test 3 to not use "bundle":

diff --git a/test cases/rust/3 staticlib/meson.build b/test cases/rust/3 staticlib/meson.build
index cf8e1032e..1710fa865 100644
--- a/test cases/rust/3 staticlib/meson.build   
+++ b/test cases/rust/3 staticlib/meson.build   
@@ -2,6 +2,6 @@ project('rust static library', 'rust', 'c')
 
 o = static_library('other', 'other.rs')
 v = static_library('value', 'value.c')
-l = static_library('stuff', 'stuff.rs', link_whole : [o, v], install : true)
+l = static_library('stuff', 'stuff.rs', link_with : [o, v])

./meson.py 'test cases/rust/3 staticlib' builddir && ninja -C builddir

Expected behavior
libother.rlib is compiled with -lstatic:-bundle,+verbatim=libvalue.a

but verbatim is problematic given that system linkers will behave differently:
https://doc.rust-lang.org/stable/rustc/command-line-arguments.html#linking-modifiers-verbatim

If instead, it were to compile with -lstatic:-bundle=value, then it should work with both GNU ld or Apple ld.

btw, why not add rust to macos CI brew installation to cover rust?

system parameters

  • meson 1.9.99 3734ff4
  • rustc 1.89.0 (29483883e 2025-08-04) (Homebrew)
  • @(#)PROGRAM:ld PROJECT:ld-1115.7.3

CC @bonzini

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS:macosIssues specific to Apple Operating Systems like MacOS and iOSOS:windowsWinodows OS specific issuesbugdynamic linkersDynamic linkers (ld, link, lld-link, etc)language:rust

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions