forked from wasmerio/wasmer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
121 lines (94 loc) · 3.68 KB
/
justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Install the environment to develop the extension.
prelude:
#!/usr/bin/env bash
set -x
pip3 install virtualenv
virtualenv .env
if test -d .env/bin/; then source .env/bin/activate; else source .env/Scripts/activate; fi
pip3 install maturin pytest pytest-benchmark twine git+https://github.com/Hywan/pdoc@submodule-for-extension
which maturin
maturin --version
which python
python --version
which python-config
python-config --abiflags || true
pwd
ls -l .env
build_features := ""
# Compile and install all the Python packages.
build-all rust_target='':
just build api {{rust_target}}
just build compiler-cranelift {{rust_target}}
just build compiler-llvm {{rust_target}}
just build compiler-singlepass {{rust_target}}
# Compile and install the Python package. Run with `--set build_features` to compile with specific Cargo features.
build package='api' rust_target='':
#!/usr/bin/env bash
export PYTHON_SYS_EXECUTABLE=$(which python)
build_features="{{build_features}}"
build_args=""
if test ! -z "${build_features}"; then
build_args="--no-default-features --features ${build_features}"
fi
if test ! -z "{{ rust_target }}"; then
build_args="${build_args} --target {{ rust_target }}"
fi
echo "Build arguments: ${build_args}"
cd packages/{{package}}/
maturin develop --binding-crate pyo3 --release --strip --cargo-extra-args="${build_args}"
# Build all the wheels.
build-all-wheels python_version rust_target:
just build-wheel api {{python_version}} {{rust_target}}
just build-wheel compiler-cranelift {{python_version}} {{rust_target}}
just build-wheel compiler-llvm {{python_version}} {{rust_target}}
just build-wheel compiler-singlepass {{python_version}} {{rust_target}}
# Build the wheel of a specific package.
build-wheel package python_version rust_target:
#!/usr/bin/env bash
export PYTHON_SYS_EXECUTABLE=$(which python)
build_features="{{build_features}}"
build_args=""
if test ! -z "${build_features}"; then
build_args="--no-default-features --features ${build_features}"
fi
echo "Build arguments: ${build_args}"
cd packages/{{package}}
maturin build --bindings pyo3 --release --target "{{ rust_target }}" --strip --cargo-extra-args="${build_args}" --interpreter "{{python_version}}"
# Create a distribution of wasmer that can be installed anywhere (it will fail on import)
build-any-wheel:
mkdir -p ./target/wheels/
cp packages/api/README.md packages/any/api_README.md
cd packages/any/ && pip3 wheel . --wheel-dir ../../target/wheels/
# Run Python.
python-run file='':
@python {{file}}
# Run the tests.
test files='tests':
@py.test -v -s {{files}}
# Run one or more benchmarks.
benchmark benchmark-filename='':
@py.test benchmarks/{{benchmark-filename}}
# Generate the documentation.
doc:
@pdoc --html --output-dir docs/api --force \
wasmer \
wasmer_compiler_cranelift \
wasmer_compiler_llvm \
wasmer_compiler_singlepass
publish repository +WHEELS:
twine upload --username wasmer --repository {{repository}} {{WHEELS}}
publish-any repository='testpypi':
twine upload --username wasmer --repository {{repository}} target/wheels/wasmer-*-py3-none-any.whl
# Compile a Rust program to Wasm.
compile-wasm FILE='examples/simple':
#!/usr/bin/env bash
set -euo pipefail
rustc --target wasm32-unknown-unknown -O --crate-type=cdylib {{FILE}}.rs -o {{FILE}}.raw.wasm
wasm-gc {{FILE}}.raw.wasm {{FILE}}.wasm
wasm-opt -Os --strip-producers {{FILE}}.wasm -o {{FILE}}.opt.wasm
mv {{FILE}}.opt.wasm {{FILE}}.wasm
rm {{FILE}}.raw.wasm
# Local Variables:
# mode: makefile
# End:
# vim: set ft=make :