-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
63 lines (53 loc) · 1.73 KB
/
main.py
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
import urllib.request
import tomllib
from pathlib import Path
from typing import Any
import sys
import subprocess
import shutil
ROOT = Path(__file__).parent
RUST = ROOT / "rust"
STAGE1_RUSTLIB = RUST / "build/host/stage1/lib/rustlib/"
def run(
args: list[str | Path], check: bool = True, **kwargs: Any
) -> subprocess.CompletedProcess[Any]:
print(">", " ".join(str(x) for x in args))
result = subprocess.run(args, check=False, text=True, **kwargs)
if check and result.returncode:
sys.exit(result.returncode)
return result
def main(emcc_version, date):
print(
"> Requesting",
f"http://static.rust-lang.org/dist/{date}/channel-rust-nightly.toml",
)
with urllib.request.urlopen(
f"http://static.rust-lang.org/dist/{date}/channel-rust-nightly.toml"
) as response:
manifest = response.read().decode()
rust = tomllib.loads(manifest)["pkg"]["rust"]
commit_hash = rust["git_commit_hash"]
if not RUST.exists():
run(
[
"git",
"clone",
"https://github.com/rust-lang/rust.git",
"--shallow-since=2025-01-01",
],
cwd=ROOT,
)
run(["git", "reset", "--hard"], cwd=RUST)
run(["git", "checkout", commit_hash], cwd=RUST)
run(["patch", "-p1", "-i", ROOT / "turn-on-emscripten-wasm-eh.patch"], cwd=RUST)
print("> cp config.toml rust")
shutil.copy("config.toml", RUST)
run(["./x.py", "build", "library", "--stage", "1"], cwd=RUST)
shutil.make_archive(
f"emcc-{emcc_version}_nightly-{date}",
"bztar",
root_dir=STAGE1_RUSTLIB,
base_dir="wasm32-unknown-emscripten",
)
if __name__ == "__main__":
main(*sys.argv[-2:])