Skip to content

Commit

Permalink
Explicitly exclude wasip1 instead of including wasip2
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Jul 10, 2024
1 parent cb76384 commit 92a3ba6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions clang/lib/Driver/ToolChains/WebAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ std::string wasm::Linker::getLinkerPath(const ArgList &Args) const {
return ToolChain.GetProgramPath(ToolChain.getDefaultLinker());
}

static bool IsWasip2(const llvm::Triple &TargetTriple) {
return TargetTriple.getOSName() == "wasip2";
static bool TargetBuildsComponents(const llvm::Triple &TargetTriple) {
// WASIp2 and above are all based on components, so test for WASI but exclude
// the original `wasi` target in addition to the `wasip1` name.
return TargetTriple.isOSWASI()
&& TargetTriple.getOSName() != "wasip1"
&& TargetTriple.getOSName() != "wasi";
}

void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
Expand Down Expand Up @@ -165,7 +169,7 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
// Don't use wasm-opt by default on `wasip2` as it doesn't have support for
// components at this time. Retain the historical default otherwise, though,
// of running `wasm-opt` by default.
bool WasmOptDefault = !IsWasip2(ToolChain.getTriple());
bool WasmOptDefault = !TargetBuildsComponents(ToolChain.getTriple());
bool RunWasmOpt = Args.hasFlag(options::OPT_wasm_opt,
options::OPT_no_wasm_opt, WasmOptDefault);

Expand Down Expand Up @@ -251,7 +255,7 @@ WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple,
}

const char *WebAssembly::getDefaultLinker() const {
if (IsWasip2(getTriple()))
if (TargetBuildsComponents(getTriple()))
return "wasm-component-ld";
return "wasm-ld";
}
Expand Down

0 comments on commit 92a3ba6

Please sign in to comment.