Skip to content

Commit 20a16aa

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 5fa53d0 commit 20a16aa

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

lib/Driver/UnixToolChains.cpp

Lines changed: 6 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,10 +1310,30 @@ elif run_os == 'wasi':
13101310

13111311
config.target_object_format = "wasm"
13121312
config.target_shared_library_prefix = 'lib'
1313-
config.target_shared_library_suffix = ".so"
1313+
config.target_shared_library_suffix = ".a"
13141314
config.target_sdk_name = "wasi"
13151315
config.target_runtime = "native"
13161316

1317+
# Exclude test cases that use objc-interop because clang doesn't support it
1318+
# with WebAssembly binary file yet.
1319+
testfiles = glob.glob(os.path.join(config.test_source_root, "**", "*.swift"))
1320+
1321+
def use_objc_interop(path):
1322+
with open(path) as f:
1323+
return '-enable-objc-interop' in f.read()
1324+
1325+
import fnmatch
1326+
def objc_interop_enabled_filenames(path, filename_pat):
1327+
matches = []
1328+
for root, dirnames, filenames in os.walk(path):
1329+
for filename in fnmatch.filter(filenames, filename_pat):
1330+
filepath = os.path.join(root, filename)
1331+
if not use_objc_interop(filepath): continue
1332+
matches.append(filename)
1333+
return matches
1334+
1335+
config.excludes += objc_interop_enabled_filenames(config.test_source_root, "*.swift")
1336+
13171337
config.target_swift_autolink_extract = inferSwiftBinary("swift-autolink-extract")
13181338

13191339
config.target_build_swift = ' '.join([
@@ -1330,7 +1350,7 @@ elif run_os == 'wasi':
13301350
config.target_build_swift_dylib = (
13311351
"%s -parse-as-library -emit-library -o '\\1'"
13321352
% (config.target_build_swift))
1333-
config.target_add_rpath = r'-Xlinker -rpath -Xlinker \1'
1353+
config.target_add_rpath = ''
13341354
config.target_swift_frontend = (
13351355
'%s -frontend -target %s %s %s %s %s '
13361356
% (config.swift, config.variant_triple, resource_dir_opt, mcp_opt,

tools/sil-func-extractor/SILFunctionExtractor.cpp

Lines changed: 2 additions & 0 deletions
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)