forked from semios/semios-packages
78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
import os
|
|
import shutil
|
|
import subprocess
|
|
|
|
from lib.make import *
|
|
from lib import arch
|
|
|
|
|
|
upstream_version = "1.97.1"
|
|
|
|
version(upstream_version)
|
|
description("A language empowering everyone to build reliable and efficient software")
|
|
maintainer("sisungo <[email protected]>")
|
|
source_url(f"https://static.rust-lang.org/dist/rustc-{upstream_version}-src.tar.xz")
|
|
|
|
builddep("shortcut/cmake")
|
|
builddep("shortcut/c++")
|
|
builddep("python")
|
|
builddep(f"libz-ng-dev @{arch.get_target()}")
|
|
builddep(f"linux-dev @{arch.get_target()}")
|
|
builddep(f"libunwind-dev @{arch.get_target()}")
|
|
builddep("curl")
|
|
builddep("grep")
|
|
builddep("sed")
|
|
|
|
|
|
def setup_musl_root():
|
|
os.makedirs("../musl_root/lib", exist_ok=True)
|
|
for i in ["libc.a", "crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o", "libunwind.a"]:
|
|
shutil.copy2(f"/lib/{arch.get_target()}/{i}", f"../musl_root/lib/{i}")
|
|
|
|
def configure():
|
|
with open("../../bootstrap.toml.in") as file:
|
|
content = file.read()
|
|
content = content.replace("%RUSTVERSION%", upstream_version)
|
|
content = content.replace("%CARGOPATH%", shutil.which("cargo") or "cargo")
|
|
content = content.replace("%RUSTCPATH%", shutil.which("rustc") or "rustc")
|
|
content = content.replace("%INSTALLPREFIX%", get_prefix("rust"))
|
|
content = content.replace("%MUSLROOT%", os.getcwd() + "/../musl_root")
|
|
with open("bootstrap.toml", "wt+") as file:
|
|
file.write(content)
|
|
|
|
def run_build():
|
|
subprocess.run(["python3", "x.py", "build"], check=True)
|
|
|
|
def run_install():
|
|
os.environ["DESTDIR"] = os.getcwd() + "/../install_destdir"
|
|
subprocess.run(["python3", "x.py", "install"], check=True)
|
|
os.chdir(os.environ["DESTDIR"])
|
|
# FIXME: Rust seemed not to process our directory name correctly, it is installed to pkg/rust.
|
|
os.chdir("pkg/rust")
|
|
|
|
|
|
def build():
|
|
setup_musl_root()
|
|
configure()
|
|
run_build()
|
|
run_install()
|
|
|
|
on_build(build)
|
|
|
|
|
|
def pack_rust(composer):
|
|
composer.makedir("lib")
|
|
composer.makedir("bin")
|
|
for i in os.listdir("."):
|
|
if ".so" in i:
|
|
composer.addfile(i, f"lib/{i}")
|
|
elif i in ["rustc", "rust-gdb", "rust-gdbgui", "rust-lldb", "rustdoc"]:
|
|
composer.addfile(i, f"bin/{i}")
|
|
composer.add_dir("rustlib", "lib/rustlib")
|
|
|
|
package("rust")
|
|
dep("semi-libc @same-arch")
|
|
dep("libz @same-arch")
|
|
dep("libcxx @same-arch")
|
|
on_pack(pack_rust)
|