@@ -7,6 +7,7 @@ pub fn addTests(step: *Step, opts: Options) void {
77 step .dependOn (testBuildVersionIOS (b , opts ));
88 step .dependOn (testDeadStrip (b , opts ));
99 step .dependOn (testDeadStripDylibs (b , opts ));
10+ step .dependOn (testDedupDylibs (b , opts ));
1011 step .dependOn (testDylib (b , opts ));
1112 step .dependOn (testDylibReexport (b , opts ));
1213 step .dependOn (testDylibReexportDeep (b , opts ));
@@ -384,6 +385,60 @@ fn testDeadStripDylibs(b: *Build, opts: Options) *Step {
384385 return test_step ;
385386}
386387
388+ fn testDedupDylibs (b : * Build , opts : Options ) * Step {
389+ const test_step = b .step ("test-macho-dedup-dylibs" , "" );
390+
391+ const obj = cc (b , "a.o" , opts );
392+ obj .addArg ("-c" );
393+ obj .addCSource (
394+ \\char world[] = "world";
395+ \\char* hello() {
396+ \\ return "Hello";
397+ \\}
398+ );
399+
400+ const dylib = ld (b , "liba.dylib" , opts );
401+ dylib .addFileSource (obj .getFile ());
402+ dylib .addArgs (&.{
403+ "-dynamic" ,
404+ "-syslibroot" ,
405+ opts .macos_sdk ,
406+ "-dylib" ,
407+ "-install_name" ,
408+ "@rpath/liba.dylib" ,
409+ "-lSystem" ,
410+ "-lSystem" ,
411+ "-lc" ,
412+ });
413+
414+ const check = dylib .check ();
415+ check .checkInHeaders ();
416+ // Check that we only have one copy of libSystem present
417+ check .checkContains ("libSystem" );
418+ check .checkNotPresent ("libSystem" );
419+ test_step .dependOn (& check .step );
420+
421+ const exe = cc (b , "main" , opts );
422+ exe .addCSource (
423+ \\#include<stdio.h>
424+ \\char* hello();
425+ \\extern char world[];
426+ \\int main() {
427+ \\ printf("%s %s", hello(), world);
428+ \\ return 0;
429+ \\}
430+ );
431+ exe .addArg ("-la" );
432+ exe .addPrefixedDirectorySource ("-L" , dylib .getDir ());
433+ exe .addPrefixedDirectorySource ("-Wl,-rpath," , dylib .getDir ());
434+
435+ const run = exe .run ();
436+ run .expectStdOutEqual ("Hello world" );
437+ test_step .dependOn (run .step ());
438+
439+ return test_step ;
440+ }
441+
387442fn testDylib (b : * Build , opts : Options ) * Step {
388443 const test_step = b .step ("test-macho-dylib" , "" );
389444
@@ -2801,7 +2856,6 @@ fn testSearchStrategy(b: *Build, opts: Options) *Step {
28012856 const obj = cc (b , "a.o" , opts );
28022857 obj .addArg ("-c" );
28032858 obj .addCSource (
2804- \\#include<stdio.h>
28052859 \\char world[] = "world";
28062860 \\char* hello() {
28072861 \\ return "Hello";
0 commit comments