|
2 | 2 | # NOTE: This file must not be called `corrosion.cmake`, because otherwise it'll be called recursively instead of the |
3 | 3 | # same-named one coming with Corrosion. |
4 | 4 |
|
5 | | -set(Rust_CARGO_TARGET wasm32-wasi) |
6 | 5 | # Necessary to make cross-compiling to wasm32-wasi work for crates with -sys dependencies. |
7 | 6 | set(Rust_CARGO_TARGET_LINK_NATIVE_LIBS "") |
8 | 7 |
|
9 | | -file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/rust-toolchain.toml" Rust_TOOLCHAIN REGEX "^channel ?=") |
10 | | -string(REGEX MATCH "[0-9.]+" Rust_TOOLCHAIN "${Rust_TOOLCHAIN}") |
11 | | -execute_process(COMMAND rustup toolchain install ${Rust_TOOLCHAIN}) |
12 | | -execute_process(COMMAND rustup target add --toolchain ${Rust_TOOLCHAIN} wasm32-wasi) |
| 8 | +# Parse Rust version and target from rust-toolchain.toml. |
| 9 | +file(READ "${CMAKE_CURRENT_SOURCE_DIR}/rust-toolchain.toml" RUST_TOOLCHAIN_FILE) |
| 10 | +if (NOT ${RUST_TOOLCHAIN_FILE} MATCHES [[channel *= *"([^\"]+)\"]]) |
| 11 | + message(FATAL_ERROR "Couldn't parse Rust toolchain version from file ${CMAKE_CURRENT_SOURCE_DIR}/rust-toolchain.toml") |
| 12 | +endif() |
| 13 | +set(Rust_TOOLCHAIN ${CMAKE_MATCH_1}) |
13 | 14 |
|
14 | | -CPMAddPackage("gh:corrosion-rs/corrosion#be76480232216a64f65e3b1d9794d68cbac6c690") |
| 15 | +if (NOT ${RUST_TOOLCHAIN_FILE} MATCHES [[targets = *\[ *"([^\"]+)]]) |
| 16 | + message(FATAL_ERROR "Couldn't parse Rust target from file ${CMAKE_CURRENT_SOURCE_DIR}/rust-toolchain.toml") |
| 17 | +endif() |
| 18 | +set(Rust_CARGO_TARGET ${CMAKE_MATCH_1}) |
| 19 | + |
| 20 | +if (NOT Rust_VERSION VERSION_EQUAL ${Rust_TOOLCHAIN}) |
| 21 | + execute_process(COMMAND rustup toolchain install ${Rust_TOOLCHAIN}) |
| 22 | +endif() |
| 23 | +execute_process(COMMAND rustup target add --toolchain ${Rust_TOOLCHAIN} ${Rust_CARGO_TARGET}) |
| 24 | + |
| 25 | +CPMAddPackage("gh:corrosion-rs/corrosion#b45275c8b5ee16118008a6a140ce842557b3e47a") |
15 | 26 | string(TOLOWER ${Rust_CARGO_HOST_ARCH} HOST_ARCH) |
0 commit comments