Skip to content

Commit 4bb11cb

Browse files
Merge remote-tracking branch 'swiftwasm/release/5.3' into katei-merge-5.3
2 parents 335c349 + 6446e64 commit 4bb11cb

28 files changed

+377
-71
lines changed

cmake/modules/DarwinSDKs.cmake

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,6 @@ set(SUPPORTED_WATCHOS_ARCHS "armv7k")
1616
set(SUPPORTED_WATCHOS_SIMULATOR_ARCHS "i386;arm64")
1717
set(SUPPORTED_OSX_ARCHS "x86_64;arm64;arm64e")
1818

19-
# Get the SDK version from SDKSettings.
20-
execute_process(
21-
COMMAND "defaults" "read" "${CMAKE_OSX_SYSROOT}/SDKSettings.plist" "Version"
22-
OUTPUT_VARIABLE SWIFT_OSX_SDK_VERSION
23-
OUTPUT_STRIP_TRAILING_WHITESPACE)
24-
25-
# Remove the last component, if any. e.g. 10.15.26 -> 10.15
26-
string(REGEX REPLACE "\([0-9]*[.][0-9]*\)[.][0-9]*" "\\1"
27-
SWIFT_OSX_SDK_VERSION "${SWIFT_OSX_SDK_VERSION}")
28-
29-
if (${SWIFT_OSX_SDK_VERSION} STREQUAL "10.14" OR
30-
${SWIFT_OSX_SDK_VERSION} STREQUAL "10.15")
31-
set(SUPPORTED_OSX_ARCHS "x86_64")
32-
else()
33-
set(SUPPORTED_OSX_ARCHS "x86_64;arm64e")
34-
endif()
35-
3619
is_sdk_requested(OSX swift_build_osx)
3720
if(swift_build_osx)
3821
configure_sdk_darwin(

include/swift/AST/DiagnosticEngine.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,19 @@ namespace swift {
10251025
}
10261026
}
10271027

1028-
bool hasDiagnostics() const {
1029-
return std::distance(Engine.TentativeDiagnostics.begin() +
1030-
PrevDiagnostics,
1031-
Engine.TentativeDiagnostics.end()) > 0;
1028+
bool hasErrors() const {
1029+
ArrayRef<Diagnostic> diagnostics(Engine.TentativeDiagnostics.begin() +
1030+
PrevDiagnostics,
1031+
Engine.TentativeDiagnostics.end());
1032+
1033+
for (auto &diagnostic : diagnostics) {
1034+
auto behavior = Engine.state.determineBehavior(diagnostic.getID());
1035+
if (behavior == DiagnosticState::Behavior::Fatal ||
1036+
behavior == DiagnosticState::Behavior::Error)
1037+
return true;
1038+
}
1039+
1040+
return false;
10321041
}
10331042

10341043
/// Abort and close this transaction and erase all diagnostics

include/swift/Frontend/Frontend.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ class CompilerInvocation {
128128
bool parseArgs(ArrayRef<const char *> Args, DiagnosticEngine &Diags,
129129
SmallVectorImpl<std::unique_ptr<llvm::MemoryBuffer>>
130130
*ConfigurationFileBuffers = nullptr,
131-
StringRef workingDirectory = {});
131+
StringRef workingDirectory = {},
132+
StringRef mainExecutablePath = {});
132133

133134
/// Sets specific options based on the given serialized Swift binary data.
134135
///
@@ -213,8 +214,11 @@ class CompilerInvocation {
213214
/// Computes the runtime resource path relative to the given Swift
214215
/// executable.
215216
static void computeRuntimeResourcePathFromExecutablePath(
216-
StringRef mainExecutablePath,
217-
llvm::SmallString<128> &runtimeResourcePath);
217+
StringRef mainExecutablePath, bool shared,
218+
llvm::SmallVectorImpl<char> &runtimeResourcePath);
219+
220+
/// Appends `lib/swift[_static]` to the given path
221+
static void appendSwiftLibDir(llvm::SmallVectorImpl<char> &path, bool shared);
218222

219223
void setSDKPath(const std::string &Path);
220224

include/swift/Frontend/FrontendOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ class FrontendOptions {
301301
/// Indicates whether the action will immediately run code.
302302
static bool isActionImmediate(ActionType);
303303

304+
/// Determines whether the static or shared resource folder is used.
305+
/// When set to `true`, the default resource folder will be set to
306+
/// '.../lib/swift', otherwise '.../lib/swift_static'.
307+
bool UseSharedResourceFolder = true;
308+
304309
/// \return true if action only parses without doing other compilation steps.
305310
static bool shouldActionOnlyParse(ActionType);
306311

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,4 +719,8 @@ def target_sdk_version : Separate<["-"], "target-sdk-version">,
719719
def target_variant_sdk_version : Separate<["-"], "target-variant-sdk-version">,
720720
HelpText<"The version of target variant SDK used for compilation">;
721721

722+
723+
def use_static_resource_dir
724+
: Flag<["-"], "use-static-resource-dir">,
725+
HelpText<"Use resources in the static resource directory">;
722726
} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]

lib/Driver/Driver.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,13 @@ bool Driver::handleImmediateArgs(const ArgList &Args, const ToolChain &TC) {
22332233
commandLine.push_back(resourceDirArg->getValue());
22342234
}
22352235

2236+
if (Args.hasFlag(options::OPT_static_executable,
2237+
options::OPT_no_static_executable, false) ||
2238+
Args.hasFlag(options::OPT_static_stdlib, options::OPT_no_static_stdlib,
2239+
false)) {
2240+
commandLine.push_back("-use-static-resource-dir");
2241+
}
2242+
22362243
std::string executable = getSwiftProgramPath();
22372244

22382245
// FIXME: This bypasses mechanisms like -v and -###. (SR-12119)

lib/Driver/ToolChains.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/Driver/Compilation.h"
2323
#include "swift/Driver/Driver.h"
2424
#include "swift/Driver/Job.h"
25+
#include "swift/Frontend/Frontend.h"
2526
#include "swift/Option/Options.h"
2627
#include "clang/Basic/Version.h"
2728
#include "clang/Driver/Util.h"
@@ -523,6 +524,13 @@ ToolChain::constructInvocation(const CompileJobAction &job,
523524
Arguments.push_back("-track-system-dependencies");
524525
}
525526

527+
if (context.Args.hasFlag(options::OPT_static_executable,
528+
options::OPT_no_static_executable, false) ||
529+
context.Args.hasFlag(options::OPT_static_stdlib,
530+
options::OPT_no_static_stdlib, false)) {
531+
Arguments.push_back("-use-static-resource-dir");
532+
}
533+
526534
context.Args.AddLastArg(
527535
Arguments,
528536
options::
@@ -1256,25 +1264,19 @@ void ToolChain::getClangLibraryPath(const ArgList &Args,
12561264
void ToolChain::getResourceDirPath(SmallVectorImpl<char> &resourceDirPath,
12571265
const llvm::opt::ArgList &args,
12581266
bool shared) const {
1259-
// FIXME: Duplicated from CompilerInvocation, but in theory the runtime
1260-
// library link path and the standard library module import path don't
1261-
// need to be the same.
12621267
if (const Arg *A = args.getLastArg(options::OPT_resource_dir)) {
12631268
StringRef value = A->getValue();
12641269
resourceDirPath.append(value.begin(), value.end());
12651270
} else if (!getTriple().isOSDarwin() && !getTriple().isOSWASI() && args.hasArg(options::OPT_sdk)) {
12661271
// for WASI, sdk option points to wasi-sysroot which doesn't have Swift toolchain
12671272
StringRef value = args.getLastArg(options::OPT_sdk)->getValue();
12681273
resourceDirPath.append(value.begin(), value.end());
1269-
llvm::sys::path::append(resourceDirPath, "usr", "lib",
1270-
shared ? "swift" : "swift_static");
1274+
llvm::sys::path::append(resourceDirPath, "usr");
1275+
CompilerInvocation::appendSwiftLibDir(resourceDirPath, shared);
12711276
} else {
12721277
auto programPath = getDriver().getSwiftProgramPath();
1273-
resourceDirPath.append(programPath.begin(), programPath.end());
1274-
llvm::sys::path::remove_filename(resourceDirPath); // remove /swift
1275-
llvm::sys::path::remove_filename(resourceDirPath); // remove /bin
1276-
llvm::sys::path::append(resourceDirPath, "lib",
1277-
shared ? "swift" : "swift_static");
1278+
CompilerInvocation::computeRuntimeResourcePathFromExecutablePath(
1279+
programPath, shared, resourceDirPath);
12781280
}
12791281

12801282
StringRef libSubDir = getPlatformNameForTriple(getTriple());

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ bool ArgsToFrontendOptionsConverter::convert(
187187
Opts.EnableSourceImport |= Args.hasArg(OPT_enable_source_import);
188188
Opts.ImportUnderlyingModule |= Args.hasArg(OPT_import_underlying_module);
189189
Opts.EnableIncrementalDependencyVerifier |= Args.hasArg(OPT_verify_incremental_dependencies);
190+
Opts.UseSharedResourceFolder = !Args.hasArg(OPT_use_static_resource_dir);
190191

191192
computeImportObjCHeaderOptions();
192193
computeImplicitImportModuleNames();

lib/Frontend/CompilerInvocation.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,25 @@ swift::CompilerInvocation::CompilerInvocation() {
3939
}
4040

4141
void CompilerInvocation::computeRuntimeResourcePathFromExecutablePath(
42-
StringRef mainExecutablePath, llvm::SmallString<128> &runtimeResourcePath) {
43-
runtimeResourcePath.assign(mainExecutablePath);
42+
StringRef mainExecutablePath, bool shared,
43+
llvm::SmallVectorImpl<char> &runtimeResourcePath) {
44+
runtimeResourcePath.append(mainExecutablePath.begin(),
45+
mainExecutablePath.end());
46+
4447
llvm::sys::path::remove_filename(runtimeResourcePath); // Remove /swift
4548
llvm::sys::path::remove_filename(runtimeResourcePath); // Remove /bin
46-
llvm::sys::path::append(runtimeResourcePath, "lib", "swift");
49+
appendSwiftLibDir(runtimeResourcePath, shared);
50+
}
51+
52+
void CompilerInvocation::appendSwiftLibDir(llvm::SmallVectorImpl<char> &path,
53+
bool shared) {
54+
llvm::sys::path::append(path, "lib", shared ? "swift" : "swift_static");
4755
}
4856

4957
void CompilerInvocation::setMainExecutablePath(StringRef Path) {
5058
llvm::SmallString<128> LibPath;
51-
computeRuntimeResourcePathFromExecutablePath(Path, LibPath);
59+
computeRuntimeResourcePathFromExecutablePath(
60+
Path, FrontendOpts.UseSharedResourceFolder, LibPath);
5261
setRuntimeResourcePath(LibPath.str());
5362

5463
llvm::SmallString<128> DiagnosticDocsPath(Path);
@@ -1584,11 +1593,10 @@ static bool ParseMigratorArgs(MigratorOptions &Opts,
15841593
}
15851594

15861595
bool CompilerInvocation::parseArgs(
1587-
ArrayRef<const char *> Args,
1588-
DiagnosticEngine &Diags,
1596+
ArrayRef<const char *> Args, DiagnosticEngine &Diags,
15891597
SmallVectorImpl<std::unique_ptr<llvm::MemoryBuffer>>
15901598
*ConfigurationFileBuffers,
1591-
StringRef workingDirectory) {
1599+
StringRef workingDirectory, StringRef mainExecutablePath) {
15921600
using namespace options;
15931601

15941602
if (Args.empty())
@@ -1619,6 +1627,10 @@ bool CompilerInvocation::parseArgs(
16191627
return true;
16201628
}
16211629

1630+
if (!mainExecutablePath.empty()) {
1631+
setMainExecutablePath(mainExecutablePath);
1632+
}
1633+
16221634
ParseModuleInterfaceArgs(ModuleInterfaceOpts, ParsedArgs);
16231635
SaveModuleInterfaceArgs(ModuleInterfaceOpts, FrontendOpts, ParsedArgs, Diags);
16241636

lib/FrontendTool/FrontendTool.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,17 +2078,18 @@ int swift::performFrontend(ArrayRef<const char *> Args,
20782078
}
20792079

20802080
CompilerInvocation Invocation;
2081-
std::string MainExecutablePath = llvm::sys::fs::getMainExecutable(Argv0,
2082-
MainAddr);
2083-
Invocation.setMainExecutablePath(MainExecutablePath);
20842081

20852082
SmallString<128> workingDirectory;
20862083
llvm::sys::fs::current_path(workingDirectory);
20872084

2085+
std::string MainExecutablePath =
2086+
llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
2087+
20882088
// Parse arguments.
20892089
SmallVector<std::unique_ptr<llvm::MemoryBuffer>, 4> configurationFileBuffers;
20902090
if (Invocation.parseArgs(Args, Instance->getDiags(),
2091-
&configurationFileBuffers, workingDirectory)) {
2091+
&configurationFileBuffers, workingDirectory,
2092+
MainExecutablePath)) {
20922093
return finishDiagProcessing(1, /*verifierEnabled*/ false);
20932094
}
20942095

0 commit comments

Comments
 (0)