Skip to content

Commit 71107c9

Browse files
authored
Merge pull request #39 from fermyon/improve-install
Improve install instructions
2 parents 187b477 + 091ade3 commit 71107c9

File tree

5 files changed

+54
-60
lines changed

5 files changed

+54
-60
lines changed

.github/workflows/release.yaml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,7 @@ jobs:
2727
shell: bash
2828
run: |
2929
git submodule update --init --recursive
30-
mkdir -p cpython/builddir/wasi
31-
mkdir -p cpython/builddir/build
32-
cd cpython/builddir/build
33-
../../configure --prefix=$(pwd)/install --enable-optimizations
34-
make
35-
cd ../wasi
36-
CONFIG_SITE=../../Tools/wasm/config.site-wasm32-wasi ../../Tools/wasm/wasi-env \
37-
../../configure -C --host=wasm32-unknown-wasi --build=$(../../config.guess) \
38-
--with-build-python=$(pwd)/../build/python --prefix=$(pwd)/install --disable-test-modules
39-
make
40-
make install
41-
cd ../../..
30+
./build-python.sh
4231
4332
- name: Publish CPython
4433
uses: actions/upload-artifact@v3

.github/workflows/test.yaml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,7 @@ jobs:
5656
shell: bash
5757
run: |
5858
git submodule update --init --recursive
59-
mkdir -p cpython/builddir/wasi
60-
mkdir -p cpython/builddir/build
61-
cd cpython/builddir/build
62-
../../configure --prefix=$(pwd)/install --enable-optimizations
63-
make
64-
cd ../wasi
65-
CONFIG_SITE=../../Tools/wasm/config.site-wasm32-wasi ../../Tools/wasm/wasi-env \
66-
../../configure -C --host=wasm32-unknown-wasi --build=$(../../config.guess) \
67-
--with-build-python=$(pwd)/../build/python --prefix=$(pwd)/install --disable-test-modules
68-
make
69-
make install
70-
cd ../../..
59+
./build-python.sh
7160
7261
- name: Lint
7362
shell: bash

Makefile

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
WASI_SDK_PATH ?= /opt/wasi-sdk
2+
CARGO_TARGET_DIR ?= $(shell pwd)/target
23

3-
target/release/spin-python: \
4-
target/wasm32-wasi/release/spin_python_engine.wasm \
4+
$(CARGO_TARGET_DIR)/release/spin-python: \
5+
$(CARGO_TARGET_DIR)/wasm32-wasi/release/spin_python_engine.wasm \
56
crates/spin-python-cli/build.rs \
67
crates/spin-python-cli/src/main.rs
78
cd crates/spin-python-cli && \
8-
SPIN_PYTHON_ENGINE_PATH=../../$< \
9+
SPIN_PYTHON_ENGINE_PATH=$< \
910
SPIN_PYTHON_CORE_LIBRARY_PATH=$$(pwd)/../../cpython/builddir/wasi/install/lib/python3.11 \
1011
cargo build --release $(BUILD_TARGET)
1112

12-
target/wasm32-wasi/release/spin_python_engine.wasm: \
13+
$(CARGO_TARGET_DIR)/wasm32-wasi/release/spin_python_engine.wasm: \
1314
crates/spin-python-engine/src/lib.rs \
1415
crates/spin-python-engine/build.rs \
15-
target/pyo3-config.txt
16+
$(CARGO_TARGET_DIR)/pyo3-config.txt
1617
cd crates/spin-python-engine && \
17-
PYO3_CONFIG_FILE=$$(pwd)/../../target/pyo3-config.txt \
18+
PYO3_CONFIG_FILE=$(CARGO_TARGET_DIR)/pyo3-config.txt \
1819
cargo build --release --target=wasm32-wasi
1920

20-
target/pyo3-config.txt: crates/spin-python-engine/pyo3-config.txt
21-
mkdir -p target
22-
cp $< target
21+
$(CARGO_TARGET_DIR)/pyo3-config.txt: crates/spin-python-engine/pyo3-config.txt
22+
mkdir -p $(CARGO_TARGET_DIR)
23+
cp $< $(CARGO_TARGET_DIR)
2324
if which cygpath > /dev/null; then \
2425
echo "lib_dir=$$(cygpath -w $$(pwd)/cpython/builddir/wasi)" >> $@; \
2526
else \

README.md

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@
22

33
This is an experiment to build a Spin Python SDK using CPython, Wizer, and PyO3.
44

5-
## Prerequisites
6-
7-
- [WASI SDK](https://github.com/WebAssembly/wasi-sdk) v16 or later, installed in /opt/wasi-sdk
8-
- [CPython](https://github.com/python/cpython) build prereqs (e.g. Make, Clang, etc.)
9-
- [Rust](https://rustup.rs/) (including `wasm32-wasi` target)
10-
- [Spin](https://github.com/fermyon/spin)
11-
- [pipenv](https://pypi.org/project/pipenv/) for installing Python project dependencies
12-
135
## Installing the Plugin and Running Examples
146

15-
Use the following command to install the `py2wasm` plugin and then build the spin app:
7+
Use the following command to install the `py2wasm` plugin and then build the example Spin app:
168

179
```
1810
spin plugins update
@@ -24,22 +16,20 @@ spin up
2416

2517
## Building and Running
2618

27-
First, build CPython for wasm32-wasi:
19+
### Prerequisites
2820

29-
```
30-
git submodule update --init --recursive
31-
mkdir -p cpython/builddir/wasi
32-
mkdir -p cpython/builddir/build
33-
cd cpython/builddir/build
34-
../../configure --prefix=$(pwd)/install --enable-optimizations
35-
make
36-
cd ../wasi
37-
CONFIG_SITE=../../Tools/wasm/config.site-wasm32-wasi ../../Tools/wasm/wasi-env \
38-
../../configure -C --host=wasm32-unknown-wasi --build=$(../../config.guess) \
39-
--with-build-python=$(pwd)/../build/python --prefix=$(pwd)/install --disable-test-modules
40-
make
41-
make install
42-
cd ../../..
21+
- [WASI SDK](https://github.com/WebAssembly/wasi-sdk) v16 or later, installed in /opt/wasi-sdk
22+
- [CPython](https://github.com/python/cpython) build prereqs (e.g. Make, Clang, etc.)
23+
- [Rust](https://rustup.rs/) (including `wasm32-wasi` target)
24+
- [Spin](https://github.com/fermyon/spin)
25+
- [pipenv](https://pypi.org/project/pipenv/) for installing Python project dependencies
26+
27+
### Instructions
28+
29+
First, build CPython for wasm32-wasi.
30+
31+
```bash
32+
./build-python.sh
4333
```
4434

4535
Then, build the `spin-python-cli`:
@@ -52,13 +42,13 @@ Finally, build and run the example app:
5242

5343
```
5444
cd examples/hello_world
55-
../../target/release/spin-python app -o app.wasm
45+
$CARGO_TARGET_DIR/release/spin-python app -o app.wasm
5646
spin up
5747
```
5848

59-
**Note:* `spin-python` and `py2wasm` are just different names for the same command. `spin-python` is used in the context of running the binary in a standalone context while `py2wasm` is used when the command is run via Spin. In the samples provided in the `examples` directory, the `spin build` command depends on the plugin `py2wasm` being installed. Therefore, to test the locally built `spin-python` binary, replace the build command in the `spin.toml` to invoke it using spin build.
49+
**Note:* `spin-python` and `py2wasm` are just different names for the same command. `spin-python` is used in the context of running the binary in a standalone context while `py2wasm` is used when the command is run via Spin. In the samples provided in the `examples` directory, the `spin build` command depends on the plugin `py2wasm` being installed. Therefore, to test the locally built `spin-python` binary, replace the build command in the `spin.toml` to invoke it using `spin build`.
6050

6151
```
6252
[component.build]
63-
command = "../../target/release/spin-python app -o app.wasm"
53+
command = "$CARGO_TARGET_DIR/release/spin-python app -o app.wasm"
6454
```

build-python.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
6+
EXE=python
7+
elif [[ "$OSTYPE" == "darwin"* ]]; then
8+
EXE=python.exe
9+
else
10+
echo "This script does not support $OSTYPE"
11+
fi
12+
13+
mkdir -p cpython/builddir/wasi cpython/builddir/build
14+
pushd cpython/builddir/build
15+
../../configure --prefix=$(pwd)/install --enable-optimizations
16+
make
17+
popd
18+
19+
pushd cpython/builddir/wasi
20+
CONFIG_SITE=../../Tools/wasm/config.site-wasm32-wasi ../../Tools/wasm/wasi-env \
21+
../../configure -C --host=wasm32-unknown-wasi --build=$(../../config.guess) \
22+
--with-build-python=$(pwd)/../build/$EXE --prefix=$(pwd)/install --disable-test-modules
23+
make
24+
make install
25+
popd

0 commit comments

Comments
 (0)