diff --git a/Cargo.lock b/Cargo.lock index fed2bf6f..3623d3d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1990,7 +1990,7 @@ dependencies = [ [[package]] name = "quickjs-wasm-sys" -version = "1.0.0" +version = "1.1.0-alpha.1" dependencies = [ "anyhow", "bindgen", diff --git a/Makefile b/Makefile index 424bd05d..60180c4c 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,6 @@ .PHONY: cli core test fmt clean .DEFAULT_GOAL := cli -download-wasi-sdk: - ./install-wasi-sdk.sh - install: cargo install --path crates/cli diff --git a/crates/quickjs-wasm-rs/Cargo.toml b/crates/quickjs-wasm-rs/Cargo.toml index 1151de46..826fa58e 100644 --- a/crates/quickjs-wasm-rs/Cargo.toml +++ b/crates/quickjs-wasm-rs/Cargo.toml @@ -11,7 +11,7 @@ categories = ["api-bindings"] [dependencies] anyhow = { workspace = true } -quickjs-wasm-sys = { version = "1.0.0", path = "../quickjs-wasm-sys" } +quickjs-wasm-sys = { version = "1.1.0-alpha.1", path = "../quickjs-wasm-sys" } serde = { version = "1.0", features = ["derive"] } once_cell = "1.16" diff --git a/crates/quickjs-wasm-sys/CHANGELOG.md b/crates/quickjs-wasm-sys/CHANGELOG.md index 285d8f15..e9d916a5 100644 --- a/crates/quickjs-wasm-sys/CHANGELOG.md +++ b/crates/quickjs-wasm-sys/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Added: `QUICKJS_WASM_SYS_WASI_SDK_MAJOR_VERSION` and `QUICKJS_WASM_SYS_WASI_SDK_MINOR_VERSION` build-time environment variables to control which version of the WASI SDK to use. +- Fixed: Changing the `QUICKJS_WASM_SYS_WASI_SDK_PATH` build time environment variable will trigger a rebuild of the crate. + ## 1.0.0 - 2023-05-16 No changes from 0.1.2. Just updating version to show we're confident in the existing bindings. diff --git a/crates/quickjs-wasm-sys/Cargo.toml b/crates/quickjs-wasm-sys/Cargo.toml index 11c6d1ab..be211247 100644 --- a/crates/quickjs-wasm-sys/Cargo.toml +++ b/crates/quickjs-wasm-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "quickjs-wasm-sys" -version = "1.0.0" +version = "1.1.0-alpha.1" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/crates/quickjs-wasm-sys/README.md b/crates/quickjs-wasm-sys/README.md index ee82fc69..5c17ca47 100644 --- a/crates/quickjs-wasm-sys/README.md +++ b/crates/quickjs-wasm-sys/README.md @@ -8,4 +8,4 @@ To publish this crate to crates.io, run `./publish.sh`. ## Using a custom WASI SDK -This crate can be compiled using a custom [WASI SDK](https://github.com/WebAssembly/wasi-sdk). When building this crate, set the `QUICKJS_WASM_SYS_WASI_SDK_PATH` environment variable to the absolute path where you installed the SDK. +This crate can be compiled using a custom [WASI SDK](https://github.com/WebAssembly/wasi-sdk). When building this crate, set the `QUICKJS_WASM_SYS_WASI_SDK_PATH` environment variable to the absolute path where you installed the SDK. You can also use a particular version of the WASI SDK by setting the `QUICKJS_WASM_SYS_WASI_SDK_MAJOR_VERSION` and `QUICKJS_WASM_SYS_WASI_SDK_MINOR_VERSION` environment variables to the appropriate versions. diff --git a/crates/quickjs-wasm-sys/build.rs b/crates/quickjs-wasm-sys/build.rs index b562d5d9..68f5c8c4 100644 --- a/crates/quickjs-wasm-sys/build.rs +++ b/crates/quickjs-wasm-sys/build.rs @@ -70,8 +70,17 @@ async fn download_wasi_sdk() -> Result { fs::create_dir_all(&wasi_sdk_dir)?; + const MAJOR_VERSION_ENV_VAR: &str = "QUICKJS_WASM_SYS_WASI_SDK_MAJOR_VERSION"; + const MINOR_VERSION_ENV_VAR: &str = "QUICKJS_WASM_SYS_WASI_SDK_MINOR_VERSION"; + println!("cargo:rerun-if-env-changed={MAJOR_VERSION_ENV_VAR}"); + println!("cargo:rerun-if-env-changed={MINOR_VERSION_ENV_VAR}"); + let major_version = + env::var(MAJOR_VERSION_ENV_VAR).unwrap_or(WASI_SDK_VERSION_MAJOR.to_string()); + let minor_version = + env::var(MINOR_VERSION_ENV_VAR).unwrap_or(WASI_SDK_VERSION_MINOR.to_string()); + let mut archive_path = wasi_sdk_dir.clone(); - archive_path.push("wasi-sdk.tar.gz"); + archive_path.push(format!("wasi-sdk-{major_version}-{minor_version}.tar.gz")); // Download archive if necessary if !archive_path.try_exists()? { @@ -83,8 +92,7 @@ async fn download_wasi_sdk() -> Result { other => return Err(anyhow!("Unsupported platform tuple {:?}", other)), }; - // FIXME: Make this HTTPS! - let uri = format!("https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-{}/wasi-sdk-{}.{}-{}.tar.gz", WASI_SDK_VERSION_MAJOR, WASI_SDK_VERSION_MAJOR, WASI_SDK_VERSION_MINOR, file_suffix); + let uri = format!("https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-{major_version}/wasi-sdk-{major_version}.{minor_version}-{file_suffix}.tar.gz"); let mut body = get_uri(uri).await?; let mut archive = fs::File::create(&archive_path)?; while let Some(frame) = body.frame().await { @@ -122,7 +130,9 @@ async fn download_wasi_sdk() -> Result { } async fn get_wasi_sdk_path() -> Result { - if let Ok(path) = env::var("QUICKJS_WASM_SYS_WASI_SDK_PATH") { + const WASI_SDK_PATH_ENV_VAR: &str = "QUICKJS_WASM_SYS_WASI_SDK_PATH"; + println!("cargo:rerun-if-env-changed={WASI_SDK_PATH_ENV_VAR}"); + if let Ok(path) = env::var(WASI_SDK_PATH_ENV_VAR) { return Ok(path.into()); } download_wasi_sdk().await diff --git a/install-wasi-sdk.sh b/install-wasi-sdk.sh deleted file mode 100755 index 4b11f7b7..00000000 --- a/install-wasi-sdk.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -if [[ "$(basename $(pwd))" != "javy" ]]; then - echo "Run this inside in the root of the javy repo" 1>&2 - exit 1 -fi - -# Don't try and install the wasi-sdk if the user has specified the wasi-sdk is installed elsewhere -set +u -if [[ -n "$QUICKJS_WASM_SYS_WASI_SDK_PATH" ]]; then - # Check that something is present where the user says the wasi-sdk is located - if [[ ! -d "$QUICKJS_WASM_SYS_WASI_SDK_PATH" ]]; then - echo "Download the wasi-sdk to $QUICKJS_WASM_SYS_WASI_SDK_PATH" 1>&2 - exit 1 - fi - exit 0 -fi -set -u - -PATH_TO_SDK="crates/quickjs-wasm-sys/wasi-sdk" -if [[ ! -d $PATH_TO_SDK ]]; then - TMPGZ=$(mktemp) - VERSION_MAJOR="20" - VERSION_MINOR="0" - if [[ "$(uname -s)" == "Darwin" ]]; then - curl --fail --location --silent https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${VERSION_MAJOR}/wasi-sdk-${VERSION_MAJOR}.${VERSION_MINOR}-macos.tar.gz --output $TMPGZ - else - curl --fail --location --silent https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${VERSION_MAJOR}/wasi-sdk-${VERSION_MAJOR}.${VERSION_MINOR}-linux.tar.gz --output $TMPGZ - fi - mkdir $PATH_TO_SDK - tar xf $TMPGZ -C $PATH_TO_SDK --strip-components=1 -fi