Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,12 @@ jobs:
with:
python-version: "3.14.0"

- name: Install latest Rust nightly toolchain
uses: dtolnay/rust-toolchain@nightly
with:
targets: wasm32-wasip1 wasm32-unknown-unknown

- name: Install latest Rust stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasip1 wasm32-unknown-unknown
targets: wasm32-wasip2
components: clippy, rustfmt

- name: Install Rust std source
shell: bash
run: rustup component add rust-src --toolchain nightly

- uses: Swatinem/rust-cache@v2
with:
shared-key: "rust-cache-${{ hashFiles('./Cargo.lock') }}"
Expand Down Expand Up @@ -138,20 +129,11 @@ jobs:
with:
python-version: "3.14.0"

- name: Install latest Rust nightly toolchain
uses: dtolnay/rust-toolchain@nightly
with:
targets: ${{ matrix.config.target }}

- name: Install latest Rust stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.config.target }}

- name: Install Rust std source
shell: bash
run: rustup component add rust-src --toolchain nightly

- uses: Swatinem/rust-cache@v2
if: matrix.config.os == 'ubuntu-latest' && matrix.config.arch == 'amd64'
with:
Expand Down Expand Up @@ -206,9 +188,7 @@ jobs:
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-wasip1 wasm32-unknown-unknown
rustup target add wasm32-wasip2

- name: Set up cross-compiled linux aarch64 build
if: matrix.config.target == 'aarch64-unknown-linux-gnu'
Expand Down
22 changes: 2 additions & 20 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,12 @@ jobs:
with:
python-version: "3.14.0"

- name: Install latest Rust nightly toolchain
uses: dtolnay/rust-toolchain@nightly
with:
targets: wasm32-wasip1 wasm32-unknown-unknown

- name: Install latest Rust stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasip1 wasm32-unknown-unknown
targets: wasm32-wasip2
components: clippy, rustfmt

- name: Install Rust std source
shell: bash
run: rustup component add rust-src --toolchain nightly

- uses: Swatinem/rust-cache@v2
with:
shared-key: "rust-cache-${{ hashFiles('./Cargo.lock') }}"
Expand Down Expand Up @@ -85,21 +76,12 @@ jobs:
with:
submodules: "recursive"

- name: Install latest Rust nightly toolchain
uses: dtolnay/rust-toolchain@nightly
with:
targets: wasm32-wasip1 wasm32-unknown-unknown

- name: Install latest Rust stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasip1 wasm32-unknown-unknown
targets: wasm32-wasip2
components: clippy, rustfmt

- name: Install Rust std source
shell: bash
run: rustup component add rust-src --toolchain nightly

- uses: Swatinem/rust-cache@v2
with:
shared-key: "rust-cache-${{ hashFiles('./Cargo.lock') }}"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ examples/cli/command
examples/sandbox/sandbox
examples/sandbox/sandbox.wasm
wasi-sdk
cpython
8 changes: 2 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@ channel](https://bytecodealliance.zulipchat.com/#narrow/stream/394175-SIG-Guest-
### Prerequisites

- Tools needed to build [CPython](https://github.com/python/cpython) (Make, Clang, etc.)
- [Rust](https://rustup.rs/) stable 1.71 or later *and* nightly 2023-07-27 or later, including the `wasm32-wasip1` and `wasm32-unknown-unknown` targets
- Note that we currently use the `-Z build-std` Cargo option to build the `componentize-py` runtime with position-independent code (which is not the default for `wasm32-wasip1`) and this requires using a recent nightly build of Rust.
- [Rust](https://rustup.rs/) stable 1.94 or later, including the `wasm32-wasip2` target

For Rust, something like this should work once you have `rustup`:

```shell
rustup update
rustup install nightly
rustup component add rust-src --toolchain nightly
rustup target add wasm32-wasip1 wasm32-unknown-unknown
rustup target add --toolchain nightly wasm32-wasip1 wasm32-unknown-unknown
rustup target add wasm32-wasip2
```

### Building and Running
Expand Down
46 changes: 20 additions & 26 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,15 @@ fn package_all_the_things(out_dir: &Path) -> Result<()> {
make_pyo3_config(&repo_dir)?;

make_runtime(
&repo_dir,
out_dir,
&wasi_sdk,
&cpython_wasi_dir,
false,
"libcomponentize_py_runtime_sync.so",
)?;
make_runtime(
&repo_dir,
out_dir,
&wasi_sdk,
&cpython_wasi_dir,
Expand Down Expand Up @@ -503,21 +505,17 @@ fn make_pyo3_config(repo_dir: &Path) -> Result<()> {
}

fn make_runtime(
repo_dir: &Path,
out_dir: &Path,
wasi_sdk: &Path,
cpython_wasi_dir: &Path,
async_: bool,
name: &str,
) -> Result<()> {
let mut cmd = Command::new("rustup");
cmd.current_dir("runtime")
.arg("run")
.arg("nightly")
.arg("cargo")
let mut cmd = Command::new("cargo");
cmd.current_dir(repo_dir.join("runtime"))
.arg("build")
.arg("-Z")
.arg("build-std=panic_abort,std")
.arg("--target=wasm32-wasip1");
.arg("--target=wasm32-wasip2");

if !DEBUG_RUNTIME {
cmd.arg("--release");
Expand All @@ -539,10 +537,20 @@ fn make_runtime(

let target = if async_ { "async" } else { "sync" };

let clang = wasi_sdk.join(format!("bin/{CLANG_EXECUTABLE}"));
cmd.env(
"RUSTFLAGS",
"-C relocation-model=pic -Z default-visibility=hidden --cfg pyo3_disable_reference_pool",
format!(
"--cfg pyo3_disable_reference_pool \
-Clink-args=-Wl,--skip-wit-component \
-Clink-args=-shared \
-Clink-args=-L{} \
-Clink-args=-lpython3.14 \
-Clink-self-contained=n",
cpython_wasi_dir.to_str().unwrap()
),
)
.env("CARGO_TARGET_WASM32_WASIP2_LINKER", clang)
.env("CARGO_TARGET_DIR", out_dir.join(target))
.env("PYO3_CONFIG_FILE", out_dir.join("pyo3-config.txt"));

Expand All @@ -552,26 +560,12 @@ fn make_runtime(

let build = if DEBUG_RUNTIME { "debug" } else { "release" };
let path = out_dir.join(target).join(format!(
"wasm32-wasip1/{build}/libcomponentize_py_runtime.a"
"wasm32-wasip2/{build}/componentize_py_runtime.wasm"
));

if path.exists() {
let clang = wasi_sdk.join(format!("bin/{CLANG_EXECUTABLE}"));
if clang.exists() {
run(Command::new(clang)
.arg("-shared")
.arg("-o")
.arg(out_dir.join(name))
.arg("-Wl,--whole-archive")
.arg(&path)
.arg("-Wl,--no-whole-archive")
.arg(format!("-L{}", cpython_wasi_dir.to_str().unwrap()))
.arg("-lpython3.14"))?;

compress(out_dir, name, out_dir, false)?;
} else {
bail!("no such file: {}", clang.display())
}
fs::copy(&path, out_dir.join(name))?;
compress(out_dir, name, out_dir, false)?;
} else {
bail!("no such file: {}", path.display())
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2024"

[lib]
crate-type = ["staticlib"]
crate-type = ["cdylib"]

[dependencies]
anyhow = "1.0.91"
Expand Down
Loading