-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #974 from messense/emscripten
Add support for `wasm32-unknown-emscripten` target
- Loading branch information
Showing
14 changed files
with
327 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ tags | |
test-crates/wheels/ | ||
test-crates/targets/ | ||
test-crates/venvs/ | ||
tests/pyodide/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
include Cargo.toml Cargo.lock | ||
include Readme.md | ||
include license-apache license-mit | ||
recursive-include src *.rs | ||
recursive-include src *.rs *.py | ||
recursive-include src/auditwheel *.json | ||
recursive-include src/python_interpreter *.py *.json | ||
recursive-include src/templates *.j2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import sys | ||
from pathlib import Path | ||
|
||
import nox | ||
|
||
|
||
def download_pyodide(session: nox.Session, pyodide_dir: Path) -> None: | ||
pyodide_dir.mkdir() | ||
|
||
PYODIDE_DEV = "https://pyodide-cdn2.iodide.io/dev/full/" | ||
pyodide_files = [ | ||
"pyodide.js", | ||
"packages.json", | ||
"pyodide.asm.js", | ||
"pyodide.asm.data", | ||
"pyodide.asm.wasm", | ||
"pyodide_py.tar", | ||
] | ||
with session.chdir(pyodide_dir): | ||
for file in pyodide_files: | ||
session.run("wget", "-q", PYODIDE_DEV + file, external=True) | ||
session.run("npm", "i", "node-fetch", external=True) | ||
|
||
|
||
@nox.session(name="test-emscripten") | ||
def test_emscripten(session: nox.Session): | ||
emscripten_dir = Path("./tests").resolve() | ||
pyodide_dir = emscripten_dir / "pyodide" | ||
if not pyodide_dir.exists(): | ||
download_pyodide(session, pyodide_dir) | ||
|
||
test_crates = [ | ||
"test-crates/pyo3-mixed", | ||
] | ||
for crate in test_crates: | ||
crate = Path(crate).resolve() | ||
|
||
ver = sys.version_info | ||
session.run( | ||
"cargo", | ||
"+nightly", | ||
"run", | ||
"build", | ||
"-m", | ||
str(crate / "Cargo.toml"), | ||
"--target", | ||
"wasm32-unknown-emscripten", | ||
"-i", | ||
f"python{ver.major}.{ver.minor}", | ||
external=True, | ||
) | ||
|
||
with session.chdir(emscripten_dir): | ||
session.run("node", "emscripten_runner.js", str(crate), external=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env python3 | ||
import subprocess | ||
import sys | ||
|
||
|
||
def update_args(args): | ||
# remove -lc. Not sure if it makes a difference but -lc doesn't belong here. | ||
# https://github.com/emscripten-core/emscripten/issues/17191 | ||
for i in reversed(range(len(args))): | ||
if args[i] == "c" and args[i - 1] == "-l": | ||
del args[i - 1 : i + 1] | ||
|
||
return args | ||
|
||
|
||
def main(args): | ||
args = update_args(args) | ||
return subprocess.call(["emcc"] + args) | ||
|
||
|
||
if __name__ == "__main__": | ||
args = sys.argv[1:] | ||
sys.exit(main(args)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"wasm32": [ | ||
{ | ||
"major": 3, | ||
"minor": 10, | ||
"abiflags": "", | ||
"interpreter": "cpython", | ||
"ext_suffix": ".cpython-310-wasm32-emscripten.so", | ||
"abi_tag": "310", | ||
"pointer_width": 32 | ||
}, | ||
{ | ||
"major": 3, | ||
"minor": 11, | ||
"abiflags": "", | ||
"interpreter": "cpython", | ||
"ext_suffix": ".cpython-311-wasm32-emscripten.so", | ||
"abi_tag": "311", | ||
"pointer_width": 32 | ||
} | ||
] | ||
} |
Oops, something went wrong.