rust-wasm: initial commit, version 1.74.0

This commit is contained in:
Tim Biermann 2023-11-19 09:21:21 +01:00
parent 2f61919607
commit 77ee900a14
Signed by: tb
GPG Key ID: 42F8B4E30B673606
9 changed files with 445 additions and 0 deletions

18
rust-wasm/.footprint Normal file
View File

@ -0,0 +1,18 @@
drwxr-xr-x root/root etc/
drwxr-xr-x root/root etc/revdep.d/
-rw-r--r-- root/root etc/revdep.d/rust-wasm
drwxr-xr-x root/root usr/
drwxr-xr-x root/root usr/lib/
drwxr-xr-x root/root usr/lib/rustlib/
-rw-r--r-- root/root usr/lib/rustlib/manifest-rust-std-wasm32-unknown-unknown
-rw-r--r-- root/root usr/lib/rustlib/manifest-rust-std-wasm32-wasi
drwxr-xr-x root/root usr/lib/rustlib/wasm32-unknown-unknown/
drwxr-xr-x root/root usr/lib/rustlib/wasm32-unknown-unknown/lib/
drwxr-xr-x root/root usr/lib/rustlib/wasm32-wasi/
drwxr-xr-x root/root usr/lib/rustlib/wasm32-wasi/lib/
drwxr-xr-x root/root usr/lib/rustlib/wasm32-wasi/lib/self-contained/
-rw-r--r-- root/root usr/lib/rustlib/wasm32-wasi/lib/self-contained/crt1-command.o
-rw-r--r-- root/root usr/lib/rustlib/wasm32-wasi/lib/self-contained/crt1-reactor.o
-rw-r--r-- root/root usr/lib/rustlib/wasm32-wasi/lib/self-contained/libc.a
drwxr-xr-x root/root usr/lib/rustlib/x86_64-unknown-linux-gnu/
drwxr-xr-x root/root usr/share/

1
rust-wasm/.nostrip Normal file
View File

@ -0,0 +1 @@
.*

12
rust-wasm/.signature Normal file
View File

@ -0,0 +1,12 @@
untrusted comment: verify with /etc/ports/contrib.pub
RWSagIOpLGJF39ilwxdMJI+MbX1fRxP2oa1rl6YQ+9lPgvuw+TcAyXQHXwQgzPlp+arO/saZouN9nuv3uyHvTJrNi5UPfOS9hAo=
SHA256 (Pkgfile) = d0dd600cc2e67054f4b66aa3b4ed59dcdd964a692d62827db2f48b3476198bdd
SHA256 (.footprint) = f6b3ffe267c75b6091c8bf0cfb8947e085b953b49d123db62a78707b66e7477d
SHA256 (rustc-1.74.0-src.tar.xz) = 23705e38c1a37acfd7fbb921c5dd8772619476e80d0b3b39ac8eb45bc0c33187
SHA256 (rust-std-1.73.0-x86_64-unknown-linux-gnu.tar.xz) = 96efb163a57b400152c357be0ea3a0dd902b56cc0df662b9ac951403c7c7b15b
SHA256 (rustc-1.73.0-x86_64-unknown-linux-gnu.tar.xz) = 14f383eb4d6e65ce01cc99f2c5cf5a78744239f29704f72fe84f11095af779f5
SHA256 (cargo-1.73.0-x86_64-unknown-linux-gnu.tar.xz) = 7c3ce5738d570eaea97dd3d213ea73c8beda4f0c61e7486f95e497b7b10c4e2d
SHA256 (0001-bootstrap-Change-libexec-dir.patch) = bef7b7df03d14d7ecbc95521463c1b870680a3e54238fb63679a184b56d4be83
SHA256 (0001-cargo-Change-libexec-dir.patch) = d13721d13fab60d3c80c95f740186b07cfad82af9ee9f52c17c29bf8bce0ba37
SHA256 (0002-compiler-Change-LLVM-targets.patch) = 4a4ff5c294acc0b1ca800856218770f6330a878acee72193aa456d82846a8a28
SHA256 (0004-compiler-Use-wasm-ld-for-wasm-targets.patch) = 2d3f60dc86c81d331aa7df331c29289264f57e7b3fc74a32161eff176e24b68f

View File

@ -0,0 +1,36 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: "Jan Alexander Steffens (heftig)" <heftig@archlinux.org>
Date: Thu, 6 May 2021 20:14:58 +0200
Subject: [PATCH] bootstrap: Change libexec dir
---
src/bootstrap/dist.rs | 2 +-
src/bootstrap/tool.rs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs
index 32da4ac29a46..78a5faeae04b 100644
--- a/src/bootstrap/dist.rs
+++ b/src/bootstrap/dist.rs
@@ -423,7 +423,7 @@ fn prepare_image(builder: &Builder<'_>, compiler: Compiler, image: &Path) {
},
builder.kind,
) {
- builder.install(&ra_proc_macro_srv, &image.join("libexec"), 0o755);
+ builder.install(&ra_proc_macro_srv, &image.join("lib"), 0o755);
}
let libdir_relative = builder.libdir_relative(compiler);
diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs
index e6d27757ac66..70e499bdabbe 100644
--- a/src/bootstrap/tool.rs
+++ b/src/bootstrap/tool.rs
@@ -689,7 +689,7 @@ fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
// Copy `rust-analyzer-proc-macro-srv` to `<sysroot>/libexec/`
// so that r-a can use it.
- let libexec_path = builder.sysroot(self.compiler).join("libexec");
+ let libexec_path = builder.sysroot(self.compiler).join("lib");
t!(fs::create_dir_all(&libexec_path));
builder.copy(&path, &libexec_path.join("rust-analyzer-proc-macro-srv"));

View File

@ -0,0 +1,23 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: "Jan Alexander Steffens (heftig)" <heftig@archlinux.org>
Date: Thu, 6 May 2021 20:13:31 +0200
Subject: [PATCH] cargo: Change libexec dir
---
src/cargo/util/auth/mod.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/cargo/util/auth/mod.rs b/src/cargo/util/auth/mod.rs
index 58309964f493..f621e1d643c4 100644
--- a/src/cargo/util/auth/mod.rs
+++ b/src/cargo/util/auth/mod.rs
@@ -711,7 +711,7 @@ fn sysroot_credential(
.parent()
.and_then(|p| p.parent())
.ok_or_else(|| format_err!("expected cargo path {}", cargo.display()))?;
- let exe = root.join("libexec").join(format!(
+ let exe = root.join("lib").join(format!(
"cargo-credential-{}{}",
cred_name,
std::env::consts::EXE_SUFFIX

View File

@ -0,0 +1,84 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: "Jan Alexander Steffens (heftig)" <jan.steffens@gmail.com>
Date: Fri, 12 Mar 2021 17:31:56 +0100
Subject: [PATCH] compiler: Change LLVM targets
- Change x86_64-unknown-linux-gnu to use x86_64-pc-linux-gnu
- Change i686-unknown-linux-gnu to use i686-pc-linux-gnu
Reintroduce the aliasing that was removed in 1.52.0 and alias the -pc-
triples to the -unknown- triples. This avoids defining proper -pc-
targets, as things break when this is done:
- The crate ecosystem expects the -unknown- targets. Making -pc-
rustc's host triple (and thus default target) would break various
crates.
- Firefox's build breaks when the host triple (from
`rustc --version --verbose`) is different from the target triple
(from `rustc --print target-list`) that best matches autoconf.
---
compiler/rustc_session/src/config.rs | 2 +-
compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs | 2 +-
compiler/rustc_target/src/spec/mod.rs | 9 +++++++++
.../rustc_target/src/spec/x86_64_unknown_linux_gnu.rs | 2 +-
4 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs
index f2ee52262ade..6a813c4b8707 100644
--- a/compiler/rustc_session/src/config.rs
+++ b/compiler/rustc_session/src/config.rs
@@ -1832,7 +1832,7 @@ pub fn parse_target_triple(
early_error(error_format, &format!("target file {path:?} does not exist"))
})
}
- Some(target) => TargetTriple::TargetTriple(target),
+ Some(target) => TargetTriple::from_alias(target),
_ => TargetTriple::from_triple(host_triple()),
}
}
diff --git a/compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs
index 73e536a7e4d9..af48d437533c 100644
--- a/compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs
+++ b/compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs
@@ -9,7 +9,7 @@ pub fn target() -> Target {
base.stack_probes = StackProbeType::X86;
Target {
- llvm_target: "i686-unknown-linux-gnu".into(),
+ llvm_target: "i686-pc-linux-gnu".into(),
pointer_width: 32,
data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
f64:32:64-f80:32-n8:16:32-S128"
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
index 8909cf33af91..e5b5bce4c290 100644
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -2876,6 +2876,15 @@ pub fn from_path(path: &Path) -> Result<Self, io::Error> {
Ok(TargetTriple::TargetJson { path_for_rustdoc: canonicalized_path, triple, contents })
}
+ /// Creates a target triple from its alias
+ pub fn from_alias(triple: String) -> Self {
+ match triple.as_str() {
+ "x86_64-pc-linux-gnu" => TargetTriple::from_triple("x86_64-unknown-linux-gnu"),
+ "i686-pc-linux-gnu" => TargetTriple::from_triple("i686-unknown-linux-gnu"),
+ _ => TargetTriple::TargetTriple(triple),
+ }
+ }
+
/// Returns a string triple for this target.
///
/// If this target is a path, the file name (without extension) is returned.
diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs
index a91ab365b668..d605eb9ccf81 100644
--- a/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs
+++ b/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs
@@ -14,7 +14,7 @@ pub fn target() -> Target {
| SanitizerSet::THREAD;
Target {
- llvm_target: "x86_64-unknown-linux-gnu".into(),
+ llvm_target: "x86_64-pc-linux-gnu".into(),
pointer_width: 64,
data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
.into(),

View File

@ -0,0 +1,24 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: "Jan Alexander Steffens (heftig)" <heftig@archlinux.org>
Date: Sat, 6 Nov 2021 22:42:06 +0100
Subject: [PATCH] compiler: Use wasm-ld for wasm targets
We don't ship rust-lld.
---
compiler/rustc_target/src/spec/wasm_base.rs | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/compiler/rustc_target/src/spec/wasm_base.rs b/compiler/rustc_target/src/spec/wasm_base.rs
index 341763aadbaf..dbb075affc18 100644
--- a/compiler/rustc_target/src/spec/wasm_base.rs
+++ b/compiler/rustc_target/src/spec/wasm_base.rs
@@ -89,8 +89,7 @@ macro_rules! args {
// arguments just yet
limit_rdylib_exports: false,
- // we use the LLD shipped with the Rust toolchain by default
- linker: Some("rust-lld".into()),
+ linker: Some("wasm-ld".into()),
linker_flavor: LinkerFlavor::WasmLld(Cc::No),
pre_link_args,

242
rust-wasm/Pkgfile Normal file
View File

@ -0,0 +1,242 @@
# Description: The Rust language for WebAssembly
# URL: https://www.rust-lang.org/
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on: lld rust wasi-libc
# Optional: clang ccache libgit2 polly sccache
name=rust-wasm
version=1.74.0
_date=2023-10-05
_rustc=1.73.0
_cargo=$_rustc
release=1
source=(https://static.rust-lang.org/dist/${name/-wasm/}c-$version-src.tar.xz
https://static.rust-lang.org/dist/$_date/rust-std-$_rustc-x86_64-unknown-linux-gnu.tar.xz
https://static.rust-lang.org/dist/$_date/rustc-$_rustc-x86_64-unknown-linux-gnu.tar.xz
https://static.rust-lang.org/dist/$_date/cargo-$_cargo-x86_64-unknown-linux-gnu.tar.xz
0001-bootstrap-Change-libexec-dir.patch
0001-cargo-Change-libexec-dir.patch
0002-compiler-Change-LLVM-targets.patch
0004-compiler-Use-wasm-ld-for-wasm-targets.patch)
unpack_source() { # {{{
for file in ${source[@]}; do
case ${file##*/} in
rustc-${version}-src.tar.xz)
echo "Unpacking $(get_filename $file)"
bsdtar -p -o -C ${SRC} -xf $(get_filename $file)
;;
*.tar.xz)
echo "Copying $(get_filename $file)"
mkdir -p ${SRC}/${name/-wasm/}c-$version-src/build/cache/${_date} || true
cp $(get_filename $file) ${SRC}/${name/-wasm/}c-$version-src/build/cache/${_date}
;;
*)
cp $(get_filename $file) ${SRC}
;;
esac
done
} # }}}
_check_version() { # {{{
local ERROR
local DATE="$(awk '/^.*"date": / {gsub(/"|,/, "", $2); print $2 }' $SRC/${name/-wasm/}c-$version-src/src/stage0.json)"
local RUSTC="$(awk '/^.*"version": / {gsub(/"|,/, "", $2); print $2 }' $SRC/${name/-wasm/}c-$version-src/src/stage0.json)"
printf '\033[0;32m%s\033[0m\n' "Checking versions for bootstrap compiler.."
printf '\033[0;32m%s\033[0m\n' "Got _date = $_date && _rustc = $_rustc"
if [ "$DATE" != "$_date" ]; then
printf '\e[1;31m%-6s\e[m\n' "Error: _date $_date != $DATE"
ERROR=1
fi
if [ "$RUSTC" != "$_rustc" ]; then
printf '\e[1;31m%-6s\e[m\n' "Error: _rustc $_rustc != $RUSTC"
ERROR=1
fi
[ $ERROR ] && exit 1
printf '\033[0;32m%s\033[0m\n' "Versions check out! Proceeding.."
unset DATE RUSTC ERROR
} # }}}
build() {
_check_version
cd "${name/-wasm/}c-$version-src"
# Patch cargo so credential helpers are in /usr/lib instead of /usr/libexec
patch -p1 -i $SRC/0001-bootstrap-Change-libexec-dir.patch
# Use our *-pc-linux-gnu targets, making LTO with clang simpler
patch -p1 -i $SRC/0002-compiler-Change-LLVM-targets.patch
patch -p1 -i $SRC/0004-compiler-Use-wasm-ld-for-wasm-targets.patch
# config.toml {{{
cat <<-EOF >$SRC/config.toml
changelog-seen = 2
[llvm]
ninja = true
link-shared = true
@POLLY@
@CCACHE@
[install]
prefix = "/usr"
[rust]
# LLVM crashes when passing an object through ThinLTO twice. This is triggered
# when using rust code in cross-language LTO if libstd was built using ThinLTO.
# http://blog.llvm.org/2019/09/closing-gap-cross-language-lto-between.html
# https://github.com/rust-lang/rust/issues/54872
codegen-units-std = 1
debuginfo-level-std = 2
codegen-tests = false
backtrace-on-ice = true
remap-debuginfo = true
jemalloc = true
description = "CRUX"
channel = "stable"
parallel-compiler = false
rpath = false
optimize = true
use-lld = true
lld = true
download-rustc = false
[build]
build-stage = 1
dist-stage = 2
install-stage = 2
host = ["x86_64-unknown-linux-gnu"]
target = ["wasm32-unknown-unknown", "wasm32-wasi"]
docs = false
extended = false
sanitizers = false
profiler = true
python = "/usr/bin/python3"
@CARGO@
@RUST@
@RUSTFMT@
[target.x86_64-unknown-linux-gnu]
llvm-config = "/usr/bin/llvm-config"
llvm-filecheck = "/usr/bin/FileCheck"
cc = @TARGETCC@
cxx = @TARGETCXX@
ar = @TARGETAR@
ranlib = @TARGETRANLIB@
[target.i686-unknown-linux-gnu]
llvm-config = "/usr/bin/llvm-config"
llvm-filecheck = "/usr/bin/FileCheck"
cc = @TARGETCC@
cxx = @TARGETCXX@
ar = @TARGETAR@
ranlib = @TARGETRANLIB@
[target.wasm32-wasi]
sanitizers = false
profiler = false
wasi-root = "/usr/share/wasi-sysroot"
[target.wasm32-unknown-unknown]
profiler = false
sanitizers = false
linker = "lld"
EOF
# }}}
if [ -e '/usr/bin/rustc' ]; then
if ! /usr/bin/ldd /usr/bin/rustc | grep -q -E '.*libLLVM.*.so => not found' && \
! /usr/bin/ldd /usr/bin/cargo | grep -q -E 'libgit2.so.* => not found'; then
sed -e 's|@CARGO@|cargo = "/usr/bin/cargo"|' \
-e 's|@RUST@|rustc = "/usr/bin/rustc"|' \
-e 's|@RUSTFMT@|rustfmt = "/usr/bin/rustfmt"|' \
-i $SRC/config.toml
else
sed -e 's|@CARGO@||' -e 's|@RUST@||' -e 's|@RUSTFMT@||' -i $SRC/config.toml
printf "\e[031mShared library missing, not using system rust to bootstrap.\033[0m\n"
fi
else
sed -e 's|@CARGO@||' -e 's|@RUST@||' -e 's|@RUSTFMT@||' -i $SRC/config.toml
fi
if [ -e '/usr/bin/ccache' ]; then
sed -e 's|@CCACHE@|ccache = "/usr/bin/ccache"|' -i $SRC/config.toml
PATH=$(echo ${PATH} | awk -v RS=: -v ORS=: '/ccache/ {next} {print}' | sed 's/:*$//')
else
sed -e 's|@CCACHE@||' -i $SRC/config.toml
fi
# needed for other target compilers
if prt-get isinst clang lld; then
sed -i \
-e 's|@TARGETCC@|"/usr/bin/clang"|g' \
-e 's|@TARGETCXX@|"/usr/bin/clang++"|g' \
-e 's|@TARGETAR@|"/usr/bin/llvm-ar"|g' \
-e 's|@TARGETRANLIB@|"/usr/bin/llvm-ranlib"|g' \
$SRC/config.toml
else
sed -i \
-e 's|@TARGETCC@|"/usr/bin/gcc"|g' \
-e 's|@TARGETCXX@|"/usr/bin/g++"|g' \
-e 's|@TARGETAR@|"/usr/bin/gcc-ar"|g' \
-e 's|@TARGETRANLIB@|"/usr/bin/gcc-ranlib"|g' \
$SRC/config.toml
fi
prt-get isinst polly && sed -e 's|@POLLY@|polly = true|' -i $SRC/config.toml || sed -e 's|@POLLY@||' -i $SRC/config.toml
cat $SRC/config.toml
mkdir "$PKGMK_SOURCE_DIR/rust" || true
export CARGO_HOME="$PKGMK_SOURCE_DIR/rust"
if [ -e '/usr/bin/sccache' ]; then
export RUSTC_WRAPPER='/usr/bin/sccache'
export SCCACHE_IDLE_TIMEOUT='1500'
fi
#error: field is never read: `id`
# --> src/bootstrap/lib.rs:280:5
# = note: `-D dead-code` implied by `-D warnings`
export RUSTFLAGS+=' -A dead_code'
export RUST_BACKTRACE=full
export PKG_CONFIG_ALLOW_CROSS=1
{ [ ! -e /usr/include/libssh2.h ] ||
export LIBSSH2_SYS_USE_PKG_CONFIG=1; }
/usr/bin/python3 ./x.py build --config="${SRC}"/config.toml -j ${JOBS-1}
DESTDIR=$PKG /usr/bin/python3 ./x.py --config="${SRC}"/config.toml install
# cleanup
rm -r $PKG/usr/{bin/,lib/{librustc_driver-*,libstd-*,libtest-*,rust-analyzer-proc-macro-srv}}
rm -r $PKG/usr/share/{doc,man}
rm -r $PKG/usr/lib/rustlib/{components,manifest-rustc,rust-installer-version,uninstall.sh,etc,install.log}
rm -rf $PKG/usr/lib/rustlib/x86_64-unknown-linux-gnu/bin
# Remove analysis data for libs that weren't installed
local file lib
while read -rd '' file; do
lib="${file%.json}.rlib"
lib="${lib/\/analysis\///lib/}"
if [[ ! -e $lib ]]; then
echo "missing '$lib'"
rm -v "$file"
fi
done < <(find "$PKG/usr/lib/rustlib" -path '*/analysis/*.json' -print0)
install -d $PKG/etc/revdep.d
echo "/usr/lib/rustlib/wasm32-unknown-unknown/lib" >$PKG/etc/revdep.d/$name
echo "/usr/lib/rustlib/wasm32-wasi/lib" >$PKG/etc/revdep.d/$name
#rm -rf $PKG/usr/lib/rustlib/x86_64-unknown-linux-gnu/
find $PKG/usr/lib/rustlib -type f -perm -600 -exec chmod 644 {} \+
find $PKG/usr/lib/rustlib -type f -perm -700 -exec chmod 755 {} \+
}

View File

@ -0,0 +1,5 @@
#!/bin/sh
rm -f footprint.in
mv .footprint footprint.in
grep -E -v '[a-z0-9]{16}\.(rlib|json|so)$' footprint.in > .footprint
rm -f footprint.in