Skip to content

Commit 2027187

Browse files
committed
Have the frontend and new swift-driver look in an external -sdk for non-Darwin platform runtime libraries and modules too
as done originally in #25990 with the legacy C++ Driver, but since lost in the new swift-driver. Only difference is this checks if resource directory exists in `-sdk` and falls back to default if not.
1 parent 4d7df08 commit 2027187

29 files changed

+101
-81
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
WARNING(warning_no_such_sdk,none,
2525
"no such SDK: '%0'", (StringRef))
2626

27+
WARNING(warning_no_resource_dir_in_sdk, none,
28+
" You passed in an external -sdk without a Swift runtime.\n"
29+
" Either specify a directory containing the runtime libraries with\n"
30+
" the -resource-dir flag, or use -sysroot instead to point at a C/C++\n"
31+
" sysroot alone. Falling back to this path for the Swift runtime modules\n"
32+
" and libraries:\n"
33+
" %0", (StringRef))
2734
ERROR(error_no_frontend_args, none,
2835
"no arguments provided to '-frontend'", ())
2936

lib/ClangImporter/ClangImporter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,8 @@ void importer::getNormalInvocationArguments(
768768
invocationArgStrs.push_back("-fapinotes-swift-version=" +
769769
languageVersion.asAPINotesVersionString());
770770

771-
// Prefer `-sdk` paths.
772-
if (!searchPathOpts.getSDKPath().empty()) {
771+
// Prefer `-sdk` paths for Darwin.
772+
if (triple.isOSDarwin() && !searchPathOpts.getSDKPath().empty()) {
773773
llvm::SmallString<261> path{searchPathOpts.getSDKPath()};
774774
llvm::sys::path::append(path, "usr", "lib", "swift", "apinotes");
775775

lib/Frontend/CompilerInvocation.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2282,6 +2282,7 @@ static bool validateSwiftModuleFileArgumentAndAdd(const std::string &swiftModule
22822282

22832283
static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
22842284
DiagnosticEngine &Diags,
2285+
const llvm::Triple &Triple,
22852286
const CASOptions &CASOpts,
22862287
const FrontendOptions &FrontendOpts,
22872288
StringRef workingDirectory) {
@@ -2416,6 +2417,18 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
24162417

24172418
if (const Arg *A = Args.getLastArg(OPT_resource_dir))
24182419
Opts.RuntimeResourcePath = A->getValue();
2420+
else if (!Triple.isOSDarwin() && Args.hasArg(OPT_sdk)) {
2421+
llvm::SmallString<128> SDKResourcePath(Opts.getSDKPath());
2422+
llvm::sys::path::append(
2423+
SDKResourcePath, "usr", "lib",
2424+
FrontendOpts.UseSharedResourceFolder ? "swift" : "swift_static");
2425+
// Check for eg <sdkRoot>/usr/lib/swift/
2426+
if (llvm::sys::fs::exists(SDKResourcePath))
2427+
Opts.RuntimeResourcePath = SDKResourcePath.str();
2428+
else
2429+
Diags.diagnose(SourceLoc(), diag::warning_no_resource_dir_in_sdk,
2430+
Opts.RuntimeResourcePath);
2431+
}
24192432

24202433
Opts.SkipAllImplicitImportPaths |= Args.hasArg(OPT_nostdimport);
24212434
Opts.SkipSDKImportPaths |= Args.hasArg(OPT_nostdlibimport);
@@ -4075,7 +4088,7 @@ bool CompilerInvocation::parseArgs(
40754088

40764089
ParseSymbolGraphArgs(SymbolGraphOpts, ParsedArgs, Diags, LangOpts);
40774090

4078-
if (ParseSearchPathArgs(SearchPathOpts, ParsedArgs, Diags,
4091+
if (ParseSearchPathArgs(SearchPathOpts, ParsedArgs, Diags, LangOpts.Target,
40794092
CASOpts, FrontendOpts, workingDirectory)) {
40804093
return true;
40814094
}

test/ClangImporter/sdk-apinotes.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %s -verify
1+
// RUN: %empty-directory(%t/sdk/usr/lib/swift/apinotes)
2+
// RUN: %empty-directory(%t/sdk/usr/lib/swift/%target-sdk-name)
3+
// RUN: cp -r %clang-importer-sdk-path/usr/include %t/sdk/usr
4+
// RUN: cp -r %test-resource-dir/shims %t/sdk/usr/lib/swift
5+
// RUN: cp %S/Inputs/cfuncs.apinotes %t/sdk/usr/lib/swift/apinotes
6+
// RUN: cp -r %platform-module-dir/Swift.swiftmodule %t/sdk/usr/lib/swift/%target-sdk-name/
7+
// RUN: %target-swift-frontend(mock-sdk: -sdk %t/sdk) -typecheck %s -verify -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import
28

39
import cfuncs
410

test/ModuleInterface/swift_build_sdk_interfaces/check-only-mode.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// RUN: %empty-directory(%t)
22
// RUN: mkdir -p %t/sdk/usr/lib/swift/Normal.swiftmodule
33
// RUN: mkdir -p %t/sdk/System/Library/Frameworks/FMWK.framework/Modules/FMWK.swiftmodule
4+
// RUN: cp -r %test-resource-dir/shims %t/sdk/usr/lib/swift
5+
// RUN: %empty-directory(%t/sdk/usr/lib/swift/%target-sdk-name)
6+
// RUN: cp -r %platform-module-dir/{_Concurrency,_StringProcessing,Swift,SwiftOnoneSupport}.swiftmodule %t/sdk/usr/lib/swift/%target-sdk-name/
47

58
// RUN: echo 'public func normal() {}' | %target-swift-frontend - -emit-module-interface-path %t/sdk/usr/lib/swift/Normal.swiftmodule/%target-swiftinterface-name -emit-module -o /dev/null -module-name Normal
69
// RUN: echo 'public func flat() {}' | %target-swift-frontend - -emit-module-interface-path %t/sdk/usr/lib/swift/Flat.swiftinterface -emit-module -o /dev/null -module-name Flat
@@ -13,7 +16,7 @@
1316
// CHECK-DAG: FMWK.swiftmodule
1417

1518
// RUN: %target-typecheck-verify-swift -sdk %t/sdk -Fsystem %t/sdk/System/Library/Frameworks -I %t/sdk/usr/lib/swift/ -module-cache-path %t/MCP -prebuilt-module-cache-path %t/prebuilt
16-
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/*.swiftmodule
19+
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/{Normal,Flat,FMWK}-*.swiftmodule
1720

1821
// Touch a file in the SDK (to make it look like it changed) and try again.
1922
// In -check-only mode, this should force a rebuild.

test/ModuleInterface/swift_build_sdk_interfaces/compiler-uses-prebuilt-envvar.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// RUN: %empty-directory(%t)
22
// RUN: mkdir -p %t/sdk/usr/lib/swift/Normal.swiftmodule
33
// RUN: mkdir -p %t/sdk/System/Library/Frameworks/FMWK.framework/Modules/FMWK.swiftmodule
4+
// RUN: cp -r %test-resource-dir/shims %t/sdk/usr/lib/swift
5+
// RUN: %empty-directory(%t/sdk/usr/lib/swift/%target-sdk-name)
6+
// RUN: cp -r %platform-module-dir/{_Concurrency,_StringProcessing,Swift,SwiftOnoneSupport}.swiftmodule %t/sdk/usr/lib/swift/%target-sdk-name/
47

58
// RUN: echo 'public func normal() {}' | %target-swift-frontend - -emit-module-interface-path %t/sdk/usr/lib/swift/Normal.swiftmodule/%target-swiftinterface-name -emit-module -o /dev/null -module-name Normal
69
// RUN: echo 'public func flat() {}' | %target-swift-frontend - -emit-module-interface-path %t/sdk/usr/lib/swift/Flat.swiftinterface -emit-module -o /dev/null -module-name Flat
@@ -13,7 +16,7 @@
1316
// CHECK-DAG: FMWK.swiftmodule
1417

1518
// RUN: env SWIFT_OVERLOAD_PREBUILT_MODULE_CACHE_PATH=%t/prebuilt %target-typecheck-verify-swift -sdk %t/sdk -Fsystem %t/sdk/System/Library/Frameworks -I %t/sdk/usr/lib/swift/ -module-cache-path %t/MCP
16-
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/*.swiftmodule
19+
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/{FMWK,Flat,Normal}-*.swiftmodule
1720

1821
// Touch a file in the SDK (to make it look like it changed) and try again.
1922
// This should still be able to use the prebuilt modules because they track
@@ -22,7 +25,7 @@
2225
// RUN: %{python} %S/../ModuleCache/Inputs/make-old.py %t/sdk/usr/lib/swift/Normal.swiftmodule/%target-swiftinterface-name
2326
// RUN: env SWIFT_OVERLOAD_PREBUILT_MODULE_CACHE_PATH=%t/prebuilt %target-typecheck-verify-swift -sdk %t/sdk -Fsystem %t/sdk/System/Library/Frameworks -I %t/sdk/usr/lib/swift/ -module-cache-path %t/MCP
2427
// RUN: ls %t/MCP/*.swiftmodule | %FileCheck -check-prefix CHECK-CACHE %s
25-
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/*.swiftmodule
28+
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/{FMWK,Flat,Normal}-*.swiftmodule
2629

2730
// CHECK-CACHE-DAG: Normal-{{.+}}.swiftmodule
2831
// CHECK-CACHE-DAG: Flat-{{.+}}.swiftmodule

test/ModuleInterface/swift_build_sdk_interfaces/compiler-uses-prebuilt.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// RUN: %empty-directory(%t)
22
// RUN: mkdir -p %t/sdk/usr/lib/swift/Normal.swiftmodule
33
// RUN: mkdir -p %t/sdk/System/Library/Frameworks/FMWK.framework/Modules/FMWK.swiftmodule
4+
// RUN: cp -r %test-resource-dir/shims %t/sdk/usr/lib/swift
5+
// RUN: %empty-directory(%t/sdk/usr/lib/swift/%target-sdk-name)
6+
// RUN: cp -r %platform-module-dir/{_Concurrency,_StringProcessing,Swift,SwiftOnoneSupport}.swiftmodule %t/sdk/usr/lib/swift/%target-sdk-name/
47

58
// RUN: echo 'public func normal() {}' | %target-swift-frontend - -emit-module-interface-path %t/sdk/usr/lib/swift/Normal.swiftmodule/%target-swiftinterface-name -emit-module -o /dev/null -module-name Normal
69
// RUN: echo 'public func flat() {}' | %target-swift-frontend - -emit-module-interface-path %t/sdk/usr/lib/swift/Flat.swiftinterface -emit-module -o /dev/null -module-name Flat
@@ -13,7 +16,7 @@
1316
// CHECK-DAG: FMWK.swiftmodule
1417

1518
// RUN: %target-typecheck-verify-swift -sdk %t/sdk -Fsystem %t/sdk/System/Library/Frameworks -I %t/sdk/usr/lib/swift/ -module-cache-path %t/MCP -prebuilt-module-cache-path %t/prebuilt
16-
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/*.swiftmodule
19+
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/{FMWK,Flat,Normal}-*.swiftmodule
1720

1821
// Touch a file in the SDK (to make it look like it changed) and try again.
1922
// This should still be able to use the prebuilt modules because they track
@@ -22,7 +25,7 @@
2225
// RUN: %{python} %S/../ModuleCache/Inputs/make-old.py %t/sdk/usr/lib/swift/Normal.swiftmodule/%target-swiftinterface-name
2326
// RUN: %target-typecheck-verify-swift -sdk %t/sdk -Fsystem %t/sdk/System/Library/Frameworks -I %t/sdk/usr/lib/swift/ -module-cache-path %t/MCP -prebuilt-module-cache-path %t/prebuilt
2427
// RUN: ls %t/MCP/*.swiftmodule | %FileCheck -check-prefix CHECK-CACHE %s
25-
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/*.swiftmodule
28+
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/{FMWK,Flat,Normal}-*.swiftmodule
2629

2730
// CHECK-CACHE-DAG: Normal-{{.+}}.swiftmodule
2831
// CHECK-CACHE-DAG: Flat-{{.+}}.swiftmodule

test/ModuleInterface/swift_build_sdk_interfaces/track-system-dependencies.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// RUN: %empty-directory(%t)
22
// RUN: cp -r %S/Inputs/system-dependencies-sdk %t/sdk
3+
// RUN: %empty-directory(%t/sdk/usr/lib/swift/%target-sdk-name)
4+
// RUN: cp -r %platform-module-dir/{_Concurrency,_StringProcessing,Swift,SwiftOnoneSupport}.swiftmodule %t/sdk/usr/lib/swift/%target-sdk-name/
5+
// RUN: cp -r %test-resource-dir/shims %t/sdk/usr/lib/swift
36
// RUN: echo 'import Platform; public func usesCStruct(_: SomeCStruct?) {}' | %target-swift-frontend - -emit-module-interface-path %t/sdk/usr/lib/swift/Swifty.swiftmodule/%target-swiftinterface-name -emit-module -o /dev/null -module-name Swifty -sdk %t/sdk
47

58
// RUN: %swift_build_sdk_interfaces -sdk %t/sdk -v -o %t/prebuilt
69
// RUN: ls %t/prebuilt | %FileCheck %s
710
// CHECK: Swifty.swiftmodule
811

912
// RUN: %target-typecheck-verify-swift -sdk %t/sdk -I %t/sdk/usr/lib/swift/ -module-cache-path %t/MCP -prebuilt-module-cache-path %t/prebuilt
10-
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/*.swiftmodule
13+
// RUN: %{python} %S/../ModuleCache/Inputs/check-is-forwarding-module.py %t/MCP/Swifty-*.swiftmodule
1114

1215
// Touch a file in the SDK (to make it look like it changed) and try again.
1316
// This should still be able to use the prebuilt modules because they track

test/ModuleInterface/swift_build_sdk_interfaces/xfails.test-sh

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
RUN: %empty-directory(%t)
2-
RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %S/Inputs/xfails-sdk/ -o %t/output -log-path %t | %FileCheck %s
2+
RUN: cp -r %S/Inputs/xfails-sdk %t/sdk
3+
RUN: %empty-directory(%t/sdk/usr/lib/swift/%target-sdk-name)
4+
RUN: cp -r %platform-module-dir/{_Concurrency,_StringProcessing,Swift,SwiftOnoneSupport}.swiftmodule %t/sdk/usr/lib/swift/%target-sdk-name/
5+
RUN: cp -r %test-resource-dir/shims %t/sdk/usr/lib/swift
6+
RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %t/sdk/ -o %t/output -log-path %t | %FileCheck %s
37
RUN: %FileCheck -check-prefix PRINTS-ERROR %s < %t/Bad-Bad-err.txt
4-
RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %S/Inputs/xfails-sdk/ -v -o %t/output -log-path %t | %FileCheck -check-prefix CHECK-VERBOSE %s
8+
RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %t/sdk/ -v -o %t/output -log-path %t | %FileCheck -check-prefix CHECK-VERBOSE %s
59
RUN: %FileCheck -check-prefix PRINTS-ERROR %s < %t/Bad-Bad-err.txt
610

711
CHECK: # (FAIL) {{.+}}{{\\|/}}Bad.swiftinterface
@@ -11,31 +15,31 @@ CHECK-VERBOSE-DAG: # (PASS) {{.+}}{{\\|/}}Good.swiftinterface
1115
PRINTS-ERROR: cannot find 'garbage' in scope
1216
HIDES-ERROR-NOT: cannot find 'garbage' in scope
1317

14-
RUN: %empty-directory(%t)
18+
RUN: %empty-directory(%t/output)
1519
RUN: echo '["Good"]' > %t/xfails-good.json
16-
RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %S/Inputs/xfails-sdk/ -o %t/output -xfails %t/xfails-good.json -log-path %t | %FileCheck -check-prefix=CHECK-XFAIL-GOOD %s
20+
RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %t/sdk/ -o %t/output -xfails %t/xfails-good.json -log-path %t | %FileCheck -check-prefix=CHECK-XFAIL-GOOD %s
1721
RUN: %FileCheck -check-prefix PRINTS-ERROR %s < %t/Bad-Bad-err.txt
18-
RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %S/Inputs/xfails-sdk/ -v -o %t/output -xfails %t/xfails-good.json 2> %t/stderr.txt | %FileCheck -check-prefix=CHECK-XFAIL-GOOD %s
22+
RUN: env SWIFT_EXEC=%swiftc_driver_plain not %{python} %utils/swift_build_sdk_interfaces.py %mcp_opt -sdk %t/sdk/ -v -o %t/output -xfails %t/xfails-good.json 2> %t/stderr.txt | %FileCheck -check-prefix=CHECK-XFAIL-GOOD %s
1923
RUN: %FileCheck -check-prefix PRINTS-ERROR %s < %t/Bad-Bad-err.txt
2024

2125
CHECK-XFAIL-GOOD-DAG: # (FAIL) {{.+}}{{\\|/}}Bad.swiftinterface
2226
CHECK-XFAIL-GOOD-DAG: # (UPASS) {{.+}}{{\\|/}}Good.swiftinterface
2327

24-
RUN: %empty-directory(%t)
28+
RUN: %empty-directory(%t/output)
2529
RUN: echo '["Good", "Bad"]' > %t/xfails-good-and-bad.json
26-
RUN: %swift_build_sdk_interfaces -sdk %S/Inputs/xfails-sdk/ -o %t/output -xfails %t/xfails-good-and-bad.json 2> %t/stderr.txt | %FileCheck -check-prefix=CHECK-XFAIL-GOOD-AND-BAD %s
30+
RUN: %swift_build_sdk_interfaces -sdk %t/sdk/ -o %t/output -xfails %t/xfails-good-and-bad.json 2> %t/stderr.txt | %FileCheck -check-prefix=CHECK-XFAIL-GOOD-AND-BAD %s
2731
RUN: %FileCheck -check-prefix HIDES-ERROR -allow-empty %s < %t/stderr.txt
28-
RUN: %swift_build_sdk_interfaces -sdk %S/Inputs/xfails-sdk/ -v -o %t/output -xfails %t/xfails-good-and-bad.json -log-path %t | %FileCheck -check-prefix=CHECK-XFAIL-GOOD-AND-BAD %s
32+
RUN: %swift_build_sdk_interfaces -sdk %t/sdk/ -v -o %t/output -xfails %t/xfails-good-and-bad.json -log-path %t | %FileCheck -check-prefix=CHECK-XFAIL-GOOD-AND-BAD %s
2933
RUN: %FileCheck -check-prefix PRINTS-ERROR %s < %t/Bad-Bad-err.txt
3034

3135
CHECK-XFAIL-GOOD-AND-BAD-DAG: # (XFAIL) {{.+}}{{\\|/}}Bad.swiftinterface
3236
CHECK-XFAIL-GOOD-AND-BAD-DAG: # (UPASS) {{.+}}{{\\|/}}Good.swiftinterface
3337

34-
RUN: %empty-directory(%t)
38+
RUN: %empty-directory(%t/output)
3539
RUN: echo '["Bad"]' > %t/xfails-bad.json
36-
RUN: %swift_build_sdk_interfaces -sdk %S/Inputs/xfails-sdk/ -o %t/output -xfails %t/xfails-bad.json 2> %t/stderr.txt | %FileCheck -check-prefix=CHECK-XFAIL-BAD %s
40+
RUN: %swift_build_sdk_interfaces -sdk %t/sdk/ -o %t/output -xfails %t/xfails-bad.json 2> %t/stderr.txt | %FileCheck -check-prefix=CHECK-XFAIL-BAD %s
3741
RUN: %FileCheck -check-prefix HIDES-ERROR -allow-empty %s < %t/stderr.txt
38-
RUN: %swift_build_sdk_interfaces -sdk %S/Inputs/xfails-sdk/ -v -o %t/output -xfails %t/xfails-bad.json -log-path %t | %FileCheck -check-prefix=CHECK-XFAIL-BAD-VERBOSE %s
42+
RUN: %swift_build_sdk_interfaces -sdk %t/sdk/ -v -o %t/output -xfails %t/xfails-bad.json -log-path %t | %FileCheck -check-prefix=CHECK-XFAIL-BAD-VERBOSE %s
3943
RUN: %FileCheck -check-prefix PRINTS-ERROR %s < %t/Bad-Bad-err.txt
4044

4145
CHECK-XFAIL-BAD: # (XFAIL) {{.+}}{{\\|/}}Bad.swiftinterface

0 commit comments

Comments
 (0)