Skip to content

Commit 3bbc504

Browse files
authored
Add -no-toolchain-stdlib-rpath flag. (#27207)
Add `-no-toolchain-stdlib-rpath` flag: the negative version of `-toolchain-stdlib-rpath`. Make `-no-toolchain-stdlib-rpath` be the default: use `/usr/lib/swift` as default RPATH on Darwin platforms instead of toolchain standard library. Adapted from #27206. tensorflow branch requires the opposite default (use toolchain standard library as RPATH) because some stdlib modules like TensorFlow do not exist in `/usr/lib/swift`.
1 parent b44158c commit 3bbc504

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

include/swift/Option/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ def no_static_stdlib: Flag<["-"], "no-static-stdlib">,
508508
def toolchain_stdlib_rpath: Flag<["-"], "toolchain-stdlib-rpath">,
509509
Flags<[HelpHidden,DoesNotAffectIncrementalBuild]>,
510510
HelpText<"Add an rpath entry for the toolchain's standard library, rather than the OS's">;
511+
def no_toolchain_stdlib_rpath: Flag<["-"], "no-toolchain-stdlib-rpath">,
512+
Flags<[HelpHidden,DoesNotAffectIncrementalBuild]>,
513+
HelpText<"Do not add an rpath entry for the toolchain's standard library (default)">;
511514
def no_stdlib_rpath: Flag<["-"], "no-stdlib-rpath">,
512515
Flags<[HelpHidden,DoesNotAffectIncrementalBuild]>,
513516
HelpText<"Don't add any rpath entries.">;

lib/Driver/DarwinToolChains.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ toolchains::Darwin::addArgsToLinkStdlib(ArgStringList &Arguments,
389389
Arguments.push_back(context.Args.MakeArgString(path));
390390
}
391391

392-
if (context.Args.hasArg(options::OPT_toolchain_stdlib_rpath)) {
392+
if (context.Args.hasFlag(options::OPT_toolchain_stdlib_rpath,
393+
options::OPT_no_toolchain_stdlib_rpath, false)) {
393394
// If the user has explicitly asked for a toolchain stdlib, we should
394395
// provide one using -rpath. This used to be the default behaviour but it
395396
// was considered annoying in at least the SwiftPM scenario (see

test/Driver/linker-rpath.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
// RUN: %swiftc_driver_plain -driver-print-jobs -toolchain-stdlib-rpath -target x86_64-apple-macosx10.9 %S/../Inputs/empty.swift -resource-dir garbage/ | %FileCheck -check-prefix TOOLCHAIN-RPATH -DPLATFORM=%target-sdk-name %s
3838
// RUN: %swiftc_driver_plain -driver-print-jobs -toolchain-stdlib-rpath -target x86_64-apple-macosx10.15 %S/../Inputs/empty.swift -resource-dir garbage/ | %FileCheck -check-prefix TOOLCHAIN-RPATH -DPLATFORM=%target-sdk-name %s
3939

40+
// ### Test with -no-toolchain-stdlib-rpath
41+
// RUN: %swiftc_driver_plain -driver-print-jobs -no-toolchain-stdlib-rpath -target x86_64-apple-macosx10.9 %S/../Inputs/empty.swift | %FileCheck -check-prefix RPATH %s
42+
// RUN: %swiftc_driver_plain -driver-print-jobs -no-toolchain-stdlib-rpath -target x86_64-apple-macosx10.15 %S/../Inputs/empty.swift | %FileCheck -check-prefix NO-RPATH %s
43+
4044
// TOOLCHAIN-RPATH: bin/ld{{"? }}
4145
// TOOLCHAIN-RPATH-SAME: -rpath garbage/[[PLATFORM]]{{ }}
4246
// TOOLCHAIN-RPATH-SAME: -o {{[^ ]+}}

0 commit comments

Comments
 (0)