Skip to content

Commit

Permalink
Some custom WASI SDK fixes (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcharles authored Jul 13, 2023
1 parent 0e1d3b7 commit d6d9203
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion crates/quickjs-wasm-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 3 additions & 0 deletions crates/quickjs-wasm-sys/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion crates/quickjs-wasm-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/quickjs-wasm-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
18 changes: 14 additions & 4 deletions crates/quickjs-wasm-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,17 @@ async fn download_wasi_sdk() -> Result<PathBuf> {

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()? {
Expand All @@ -83,8 +92,7 @@ async fn download_wasi_sdk() -> Result<PathBuf> {
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 {
Expand Down Expand Up @@ -122,7 +130,9 @@ async fn download_wasi_sdk() -> Result<PathBuf> {
}

async fn get_wasi_sdk_path() -> Result<PathBuf> {
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
Expand Down
34 changes: 0 additions & 34 deletions install-wasi-sdk.sh

This file was deleted.

0 comments on commit d6d9203

Please sign in to comment.