Skip to content

Commit c0c3241

Browse files
Fix sil-func-extractor and driver (#28)
* [WASM] Remove rpath flag and link objects using llvm-ar instead of ar * [WASM] Disable objc interop for sil-func-extractor when targeting wasm * [WASM] Exclude test cases which use -enable-objc-interop * [WASM] Make availability_returns_twice.swift unsupoorted on wasi due to lack of setjmp
1 parent 56da0f5 commit c0c3241

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

lib/Driver/UnixToolChains.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,12 @@ toolchains::GenericUnix::constructInvocation(const StaticLinkJobAction &job,
346346
ArgStringList Arguments;
347347

348348
// Configure the toolchain.
349-
const char *AR = "ar";
349+
const char *AR;
350+
if (getTriple().isOSBinFormatWasm()) {
351+
AR = "llvm-ar";
352+
} else {
353+
AR = "ar";
354+
}
350355
Arguments.push_back("crs");
351356

352357
Arguments.push_back(

test/ClangImporter/availability_returns_twice.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-typecheck-verify-swift
22
// UNSUPPORTED: OS=windows-msvc
3+
// UNSUPPORTED: OS=wasi
34
// In Android jmp_buf is int[16], which doesn't convert to &Int (SR-9136)
45
// XFAIL: OS=linux-androideabi
56
// XFAIL: OS=linux-android

test/lit.cfg

+22-2
Original file line numberDiff line numberDiff line change
@@ -1226,10 +1226,30 @@ elif run_os == 'wasi':
12261226

12271227
config.target_object_format = "wasm"
12281228
config.target_shared_library_prefix = 'lib'
1229-
config.target_shared_library_suffix = ".so"
1229+
config.target_shared_library_suffix = ".a"
12301230
config.target_sdk_name = "wasi"
12311231
config.target_runtime = "native"
12321232

1233+
# Exclude test cases that use objc-interop because clang doesn't support it
1234+
# with WebAssembly binary file yet.
1235+
testfiles = glob.glob(os.path.join(config.test_source_root, "**", "*.swift"))
1236+
1237+
def use_objc_interop(path):
1238+
with open(path) as f:
1239+
return '-enable-objc-interop' in f.read()
1240+
1241+
import fnmatch
1242+
def objc_interop_enabled_filenames(path, filename_pat):
1243+
matches = []
1244+
for root, dirnames, filenames in os.walk(path):
1245+
for filename in fnmatch.filter(filenames, filename_pat):
1246+
filepath = os.path.join(root, filename)
1247+
if not use_objc_interop(filepath): continue
1248+
matches.append(filename)
1249+
return matches
1250+
1251+
config.excludes += objc_interop_enabled_filenames(config.test_source_root, "*.swift")
1252+
12331253
config.target_swift_autolink_extract = inferSwiftBinary("swift-autolink-extract")
12341254

12351255
config.target_build_swift = ' '.join([
@@ -1246,7 +1266,7 @@ elif run_os == 'wasi':
12461266
config.target_build_swift_dylib = (
12471267
"%s -parse-as-library -emit-library -o '\\1'"
12481268
% (config.target_build_swift))
1249-
config.target_add_rpath = r'-Xlinker -rpath -Xlinker \1'
1269+
config.target_add_rpath = ''
12501270
config.target_swift_frontend = (
12511271
'%s -frontend -target %s %s %s %s %s '
12521272
% (config.swift, config.variant_triple, resource_dir_opt, mcp_opt,

tools/sil-func-extractor/SILFunctionExtractor.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ int main(int argc, char **argv) {
249249
Invocation.getLangOptions().DisableAvailabilityChecking = true;
250250
Invocation.getLangOptions().EnableAccessControl = false;
251251
Invocation.getLangOptions().EnableObjCAttrRequiresFoundation = false;
252+
if (Invocation.getLangOptions().Target.isOSBinFormatWasm())
253+
Invocation.getLangOptions().EnableObjCInterop = false;
252254

253255
serialization::ExtendedValidationInfo extendedInfo;
254256
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =

0 commit comments

Comments
 (0)