Skip to content

Commit f46b5dc

Browse files
kateinoigakukunAnka
authored andcommitted
[wasm][Driver] HACK: Add wasi-sysroot layout and auto-detection support
Currenty, SwiftWasm toolchain contains wasi-sysroot under `./usr/share/wasi-sysroot` directory in the toolchain package, but we don't have a good consensus on the location of wasi-sysroot yet. So this patch is a temporary solution just to avoid the need to specify `-sdk` option manually. That being said, SwiftPM already passes `-sdk` option to the driver, so the option is only needed when the driver is invoked directly.
1 parent aa2e56d commit f46b5dc

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/Driver/Driver.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,13 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
17951795
});
17961796
}
17971797
}
1798+
} if (OI.SDKPath.empty() && TC.getTriple().isOSWASI()) {
1799+
llvm::SmallString<128> SDKPath;
1800+
llvm::sys::path::append(SDKPath, getSwiftProgramPath());
1801+
llvm::sys::path::remove_filename(SDKPath); // 'swift'
1802+
llvm::sys::path::remove_filename(SDKPath); // 'bin'
1803+
llvm::sys::path::append(SDKPath, "share", "wasi-sysroot");
1804+
OI.SDKPath = SDKPath.str().str();
17981805
}
17991806

18001807
if (!OI.SDKPath.empty()) {

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,8 @@ void ToolChain::getResourceDirPath(SmallVectorImpl<char> &resourceDirPath,
14481448
if (const Arg *A = args.getLastArg(options::OPT_resource_dir)) {
14491449
StringRef value = A->getValue();
14501450
resourceDirPath.append(value.begin(), value.end());
1451-
} else if (!getTriple().isOSDarwin() && args.hasArg(options::OPT_sdk)) {
1451+
} else if (!getTriple().isOSDarwin() && !getTriple().isOSWASI() && args.hasArg(options::OPT_sdk)) {
1452+
// for WASI, sdk option points to wasi-sysroot which doesn't have Swift toolchain
14521453
StringRef value = args.getLastArg(options::OPT_sdk)->getValue();
14531454
resourceDirPath.append(value.begin(), value.end());
14541455
llvm::sys::path::append(resourceDirPath, "usr");

0 commit comments

Comments
 (0)