Skip to content

Commit 06bef3c

Browse files
authored
Improve behavior for downloading build tools (#706)
* Add `-DBINDINGS_TARGET=OFF` and `-DUSE_WASM_COMPONENT_LD=OFF` to disable downloading these programs entirely. * Favor `wit-bindgen` on the system if found and if it has the right version. * Don't fail at configure-time if the arch or os of the host is unknown since the tool may not be needed during the build.
1 parent 4bd4a9b commit 06bef3c

3 files changed

Lines changed: 45 additions & 11 deletions

File tree

cmake/ba-download.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ function(ba_download target repo version)
1010
elseif (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64")
1111
set(arch "x86_64")
1212
else()
13-
message(FATAL_ERROR "Unsupported architecture ${CMAKE_HOST_SYSTEM_PROCESSOR} for ${target}")
13+
set(arch "UNKNOWN_ARCH")
14+
message(WARNING "Unsupported architecture ${CMAKE_HOST_SYSTEM_PROCESSOR} for ${target}")
1415
endif()
1516

1617
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
@@ -20,7 +21,8 @@ function(ba_download target repo version)
2021
elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
2122
set(os windows)
2223
else()
23-
message(FATAL_ERROR "Unsupported system ${CMAKE_HOST_SYSTEM_NAME} for ${target}")
24+
set(os "UNKNOWN_OS")
25+
message(WARNING "Unsupported system ${CMAKE_HOST_SYSTEM_NAME} for ${target}")
2426
endif()
2527

2628
if (target STREQUAL wasmtime)

cmake/bindings.cmake

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,40 @@
1-
include(ba-download)
1+
# Enable turning this rule off entirely if so desired.
2+
option(BINDINGS_TARGET "Generate bindings target" ON)
3+
if (NOT BINDINGS_TARGET)
4+
return()
5+
endif()
26

3-
ba_download(
4-
wit-bindgen
5-
"https://github.com/bytecodealliance/wit-bindgen"
6-
"0.48.0"
7-
)
8-
ExternalProject_Get_Property(wit-bindgen SOURCE_DIR)
9-
set(wit_bindgen "${SOURCE_DIR}/wit-bindgen")
7+
# If `wit-bindgen` is on the system and has the right version, favor that,
8+
# otherwise download a known good version.
9+
find_program(WIT_BINDGEN_EXECUTABLE NAMES wit-bindgen)
10+
if(WIT_BINDGEN_EXECUTABLE)
11+
message(STATUS "Found wit-bindgen: ${WIT_BINDGEN_EXECUTABLE}")
12+
13+
execute_process(
14+
COMMAND ${WIT_BINDGEN_EXECUTABLE} --version
15+
OUTPUT_VARIABLE WIT_BINDGEN_VERSION
16+
OUTPUT_STRIP_TRAILING_WHITESPACE)
17+
18+
if (NOT (WIT_BINDGEN_VERSION MATCHES "0\\.48\\.0"))
19+
message(WARNING "wit-bindgen version 0.48.0 is required, found: ${WIT_BINDGEN_VERSION}")
20+
set(WIT_BINDGEN_EXECUTABLE "")
21+
endif()
22+
endif()
23+
24+
if (NOT WIT_BINDGEN_EXECUTABLE)
25+
include(ba-download)
26+
ba_download(
27+
wit-bindgen
28+
"https://github.com/bytecodealliance/wit-bindgen"
29+
"0.48.0"
30+
)
31+
ExternalProject_Get_Property(wit-bindgen SOURCE_DIR)
32+
set(wit_bindgen "${SOURCE_DIR}/wit-bindgen")
33+
else()
34+
set(wit_bindgen ${WIT_BINDGEN_EXECUTABLE})
35+
endif()
1036

37+
include(ExternalProject)
1138
ExternalProject_Add(
1239
wasi-wits
1340
URL https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v0.2.0.tar.gz

cmake/wasm-component-ld.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
option(USE_WASM_COMPONENT_LD "Use wasm-component-ld as the linker for WebAssembly components" ON)
2+
if (NOT USE_WASM_COMPONENT_LD)
3+
return()
4+
endif()
5+
16
find_program(WASM_COMPONENT_LD_EXECUTABLE NAMES wasm-component-ld)
2-
include(ba-download)
37

48
if (NOT WASM_COMPONENT_LD_EXECUTABLE)
9+
include(ba-download)
510
ba_download(
611
wasm-component-ld
712
"https://github.com/bytecodealliance/wasm-component-ld"

0 commit comments

Comments
 (0)