Skip to content

Commit b335c43

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 a2bb344 commit b335c43

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
@@ -1253,10 +1253,30 @@ elif run_os == 'wasi':
12531253

12541254
config.target_object_format = "wasm"
12551255
config.target_shared_library_prefix = 'lib'
1256-
config.target_shared_library_suffix = ".so"
1256+
config.target_shared_library_suffix = ".a"
12571257
config.target_sdk_name = "wasi"
12581258
config.target_runtime = "native"
12591259

1260+
# Exclude test cases that use objc-interop because clang doesn't support it
1261+
# with WebAssembly binary file yet.
1262+
testfiles = glob.glob(os.path.join(config.test_source_root, "**", "*.swift"))
1263+
1264+
def use_objc_interop(path):
1265+
with open(path) as f:
1266+
return '-enable-objc-interop' in f.read()
1267+
1268+
import fnmatch
1269+
def objc_interop_enabled_filenames(path, filename_pat):
1270+
matches = []
1271+
for root, dirnames, filenames in os.walk(path):
1272+
for filename in fnmatch.filter(filenames, filename_pat):
1273+
filepath = os.path.join(root, filename)
1274+
if not use_objc_interop(filepath): continue
1275+
matches.append(filename)
1276+
return matches
1277+
1278+
config.excludes += objc_interop_enabled_filenames(config.test_source_root, "*.swift")
1279+
12601280
config.target_swift_autolink_extract = inferSwiftBinary("swift-autolink-extract")
12611281

12621282
config.target_build_swift = ' '.join([
@@ -1273,7 +1293,7 @@ elif run_os == 'wasi':
12731293
config.target_build_swift_dylib = (
12741294
"%s -parse-as-library -emit-library -o '\\1'"
12751295
% (config.target_build_swift))
1276-
config.target_add_rpath = r'-Xlinker -rpath -Xlinker \1'
1296+
config.target_add_rpath = ''
12771297
config.target_swift_frontend = (
12781298
'%s -frontend -target %s %s %s %s %s '
12791299
% (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)