From ab45a3cea163e1f1e8908e7d7f6e08d4d19fa046 Mon Sep 17 00:00:00 2001 From: Phil Cummins Date: Wed, 13 Nov 2024 10:35:32 +0100 Subject: [PATCH 1/6] target wasm32-wasip1 --- build.rs | 106 +++++++++++++++++++++++++++---------------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/build.rs b/build.rs index 1d1c79b..e06f162 100644 --- a/build.rs +++ b/build.rs @@ -32,64 +32,64 @@ fn main() -> Result<()> { let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); - if matches!(env::var("CARGO_CFG_FEATURE").as_deref(), Ok("cargo-clippy")) - || env::var("CLIPPY_ARGS").is_ok() - || env::var("CARGO_EXPAND_NO_RUN_NIGHTLY").is_ok() - { - stubs_for_clippy(&out_dir) - } else { - package_all_the_things(&out_dir) - }?; + // if matches!(env::var("CARGO_CFG_FEATURE").as_deref(), Ok("cargo-clippy")) + // || env::var("CLIPPY_ARGS").is_ok() + // || env::var("CARGO_EXPAND_NO_RUN_NIGHTLY").is_ok() + // { + // stubs_for_clippy(&out_dir) + // } else { + package_all_the_things(&out_dir)?; + // }?; // TODO: how can we detect `cargo test` and only run this in that case (or more specifically, run it so it // generates an empty file)? test_generator::generate() } -fn stubs_for_clippy(out_dir: &Path) -> Result<()> { - println!( - "cargo:warning=using stubbed runtime, core library, and adapter for static analysis purposes..." - ); - - let files = [ - "libcomponentize_py_runtime.so.zst", - "libpython3.12.so.zst", - "libc.so.zst", - "libwasi-emulated-mman.so.zst", - "libwasi-emulated-process-clocks.so.zst", - "libwasi-emulated-getpid.so.zst", - "libwasi-emulated-signal.so.zst", - "libc++.so.zst", - "libc++abi.so.zst", - "wasi_snapshot_preview1.reactor.wasm.zst", - ]; - - for file in files { - let path = out_dir.join(file); - - if !path.exists() { - Encoder::new(File::create(path)?, ZSTD_COMPRESSION_LEVEL)?.do_finish()?; - } - } - - let path = out_dir.join("python-lib.tar.zst"); - - if !path.exists() { - Builder::new(Encoder::new(File::create(path)?, ZSTD_COMPRESSION_LEVEL)?) - .into_inner()? - .do_finish()?; - } - - let path = out_dir.join("bundled.tar.zst"); - - if !path.exists() { - Builder::new(Encoder::new(File::create(path)?, ZSTD_COMPRESSION_LEVEL)?) - .into_inner()? - .do_finish()?; - } - - Ok(()) -} +// fn stubs_for_clippy(out_dir: &Path) -> Result<()> { +// println!( +// "cargo:warning=using stubbed runtime, core library, and adapter for static analysis purposes..." +// ); + +// let files = [ +// "libcomponentize_py_runtime.so.zst", +// "libpython3.12.so.zst", +// "libc.so.zst", +// "libwasi-emulated-mman.so.zst", +// "libwasi-emulated-process-clocks.so.zst", +// "libwasi-emulated-getpid.so.zst", +// "libwasi-emulated-signal.so.zst", +// "libc++.so.zst", +// "libc++abi.so.zst", +// "wasi_snapshot_preview1.reactor.wasm.zst", +// ]; + +// for file in files { +// let path = out_dir.join(file); + +// if !path.exists() { +// Encoder::new(File::create(path)?, ZSTD_COMPRESSION_LEVEL)?.do_finish()?; +// } +// } + +// let path = out_dir.join("python-lib.tar.zst"); + +// if !path.exists() { +// Builder::new(Encoder::new(File::create(path)?, ZSTD_COMPRESSION_LEVEL)?) +// .into_inner()? +// .do_finish()?; +// } + +// let path = out_dir.join("bundled.tar.zst"); + +// if !path.exists() { +// Builder::new(Encoder::new(File::create(path)?, ZSTD_COMPRESSION_LEVEL)?) +// .into_inner()? +// .do_finish()?; +// } + +// Ok(()) +// } fn package_all_the_things(out_dir: &Path) -> Result<()> { let repo_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); @@ -112,7 +112,7 @@ fn package_all_the_things(out_dir: &Path) -> Result<()> { .arg("-Z") .arg("build-std=panic_abort,std") .arg("--release") - .arg("--target=wasm32-wasi"); + .arg("--target=wasm32-wasip1"); for (key, _) in env::vars_os() { if key From d715cc1a45a03f44207850a38a1854b3801baa33 Mon Sep 17 00:00:00 2001 From: Phil Cummins Date: Wed, 13 Nov 2024 10:36:02 +0100 Subject: [PATCH 2/6] whoops --- build.rs | 104 +++++++++++++++++++++++++++---------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/build.rs b/build.rs index e06f162..d03ec88 100644 --- a/build.rs +++ b/build.rs @@ -32,64 +32,64 @@ fn main() -> Result<()> { let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); - // if matches!(env::var("CARGO_CFG_FEATURE").as_deref(), Ok("cargo-clippy")) - // || env::var("CLIPPY_ARGS").is_ok() - // || env::var("CARGO_EXPAND_NO_RUN_NIGHTLY").is_ok() - // { - // stubs_for_clippy(&out_dir) - // } else { - package_all_the_things(&out_dir)?; - // }?; + if matches!(env::var("CARGO_CFG_FEATURE").as_deref(), Ok("cargo-clippy")) + || env::var("CLIPPY_ARGS").is_ok() + || env::var("CARGO_EXPAND_NO_RUN_NIGHTLY").is_ok() + { + stubs_for_clippy(&out_dir) + } else { + package_all_the_things(&out_dir) + }?; // TODO: how can we detect `cargo test` and only run this in that case (or more specifically, run it so it // generates an empty file)? test_generator::generate() } -// fn stubs_for_clippy(out_dir: &Path) -> Result<()> { -// println!( -// "cargo:warning=using stubbed runtime, core library, and adapter for static analysis purposes..." -// ); - -// let files = [ -// "libcomponentize_py_runtime.so.zst", -// "libpython3.12.so.zst", -// "libc.so.zst", -// "libwasi-emulated-mman.so.zst", -// "libwasi-emulated-process-clocks.so.zst", -// "libwasi-emulated-getpid.so.zst", -// "libwasi-emulated-signal.so.zst", -// "libc++.so.zst", -// "libc++abi.so.zst", -// "wasi_snapshot_preview1.reactor.wasm.zst", -// ]; - -// for file in files { -// let path = out_dir.join(file); - -// if !path.exists() { -// Encoder::new(File::create(path)?, ZSTD_COMPRESSION_LEVEL)?.do_finish()?; -// } -// } - -// let path = out_dir.join("python-lib.tar.zst"); - -// if !path.exists() { -// Builder::new(Encoder::new(File::create(path)?, ZSTD_COMPRESSION_LEVEL)?) -// .into_inner()? -// .do_finish()?; -// } - -// let path = out_dir.join("bundled.tar.zst"); - -// if !path.exists() { -// Builder::new(Encoder::new(File::create(path)?, ZSTD_COMPRESSION_LEVEL)?) -// .into_inner()? -// .do_finish()?; -// } - -// Ok(()) -// } +fn stubs_for_clippy(out_dir: &Path) -> Result<()> { + println!( + "cargo:warning=using stubbed runtime, core library, and adapter for static analysis purposes..." + ); + + let files = [ + "libcomponentize_py_runtime.so.zst", + "libpython3.12.so.zst", + "libc.so.zst", + "libwasi-emulated-mman.so.zst", + "libwasi-emulated-process-clocks.so.zst", + "libwasi-emulated-getpid.so.zst", + "libwasi-emulated-signal.so.zst", + "libc++.so.zst", + "libc++abi.so.zst", + "wasi_snapshot_preview1.reactor.wasm.zst", + ]; + + for file in files { + let path = out_dir.join(file); + + if !path.exists() { + Encoder::new(File::create(path)?, ZSTD_COMPRESSION_LEVEL)?.do_finish()?; + } + } + + let path = out_dir.join("python-lib.tar.zst"); + + if !path.exists() { + Builder::new(Encoder::new(File::create(path)?, ZSTD_COMPRESSION_LEVEL)?) + .into_inner()? + .do_finish()?; + } + + let path = out_dir.join("bundled.tar.zst"); + + if !path.exists() { + Builder::new(Encoder::new(File::create(path)?, ZSTD_COMPRESSION_LEVEL)?) + .into_inner()? + .do_finish()?; + } + + Ok(()) +} fn package_all_the_things(out_dir: &Path) -> Result<()> { let repo_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); From db5b22d38c6e8ca326742f88e3539293dbdbae03 Mon Sep 17 00:00:00 2001 From: Phil Cummins Date: Wed, 13 Nov 2024 10:54:29 +0100 Subject: [PATCH 3/6] hmm --- .github/workflows/test.yaml | 20 ++++++++++++++++++++ build.rs | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8cba0b0..d92606a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -67,6 +67,26 @@ jobs: shell: bash run: echo "WASI_SDK_PATH=$(cygpath -m /tmp/wasi-sdk-${WASI_SDK_VERSION})" >> ${GITHUB_ENV} + - name: Restore CPython + id: cache-cpython-wasi + uses: actions/cache/restore@v4 + with: + path: cpython/builddir/wasi + key: cpython-wasi + enableCrossOsArchive: true + + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.config.maturin_target }} + args: --release --out dist --features pyo3 + manylinux: 2_28 + docker-options: -v /opt/wasi-sdk:/opt/wasi-sdk + before-script-linux: | + rustup install nightly + rustup component add rust-src --toolchain nightly + rustup target add wasm32-wasi wasm32-unknown-unknown + - name: Cache CPython id: cache-cpython-wasi uses: actions/cache@v4 diff --git a/build.rs b/build.rs index d03ec88..44b4c51 100644 --- a/build.rs +++ b/build.rs @@ -103,6 +103,12 @@ fn package_all_the_things(out_dir: &Path) -> Result<()> { make_pyo3_config(&repo_dir)?; + let mut target_list_command = Command::new("rustc"); + target_list_command.arg("--print") + .arg("target-list"); + let status = target_list_command.status()?; + assert!(status.success()); + let mut cmd = Command::new("rustup"); cmd.current_dir("runtime") .arg("run") From bc0c8e7053ac12238209eff0d29df1a19103a3d4 Mon Sep 17 00:00:00 2001 From: Phil Cummins Date: Wed, 13 Nov 2024 10:55:15 +0100 Subject: [PATCH 4/6] reverts back to wasm32-wasi --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 44b4c51..5c0cf10 100644 --- a/build.rs +++ b/build.rs @@ -118,7 +118,7 @@ fn package_all_the_things(out_dir: &Path) -> Result<()> { .arg("-Z") .arg("build-std=panic_abort,std") .arg("--release") - .arg("--target=wasm32-wasip1"); + .arg("--target=wasm32-wasi"); for (key, _) in env::vars_os() { if key From 15f1199b6c93245734f1f66e4cb5950a4143aa3b Mon Sep 17 00:00:00 2001 From: Phil Cummins Date: Wed, 13 Nov 2024 10:56:59 +0100 Subject: [PATCH 5/6] more --- .github/workflows/test.yaml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d92606a..76f6bf1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -67,14 +67,14 @@ jobs: shell: bash run: echo "WASI_SDK_PATH=$(cygpath -m /tmp/wasi-sdk-${WASI_SDK_VERSION})" >> ${GITHUB_ENV} - - name: Restore CPython + - name: Cache CPython id: cache-cpython-wasi - uses: actions/cache/restore@v4 + uses: actions/cache@v4 with: path: cpython/builddir/wasi key: cpython-wasi enableCrossOsArchive: true - + - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -87,14 +87,6 @@ jobs: rustup component add rust-src --toolchain nightly rustup target add wasm32-wasi wasm32-unknown-unknown - - name: Cache CPython - id: cache-cpython-wasi - uses: actions/cache@v4 - with: - path: cpython/builddir/wasi - key: cpython-wasi - enableCrossOsArchive: true - - name: Lint shell: bash run: bash .github/workflows/lint.sh From 61c338c65f6e6464037ddb6e6c35f44bb5beeead Mon Sep 17 00:00:00 2001 From: Phil Cummins Date: Wed, 13 Nov 2024 11:03:24 +0100 Subject: [PATCH 6/6] test --- .github/workflows/test.yaml | 4 ++-- build.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 76f6bf1..7ab28a2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -74,7 +74,7 @@ jobs: path: cpython/builddir/wasi key: cpython-wasi enableCrossOsArchive: true - + - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -85,7 +85,7 @@ jobs: before-script-linux: | rustup install nightly rustup component add rust-src --toolchain nightly - rustup target add wasm32-wasi wasm32-unknown-unknown + rustup target add wasm32-wasip1 wasm32-unknown-unknown - name: Lint shell: bash diff --git a/build.rs b/build.rs index 5c0cf10..44b4c51 100644 --- a/build.rs +++ b/build.rs @@ -118,7 +118,7 @@ fn package_all_the_things(out_dir: &Path) -> Result<()> { .arg("-Z") .arg("build-std=panic_abort,std") .arg("--release") - .arg("--target=wasm32-wasi"); + .arg("--target=wasm32-wasip1"); for (key, _) in env::vars_os() { if key