aboutsummaryrefslogtreecommitdiffstats
path: root/community/rust/check-rustc
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2017-05-01 00:43:19 +0200
committerJakub Jirutka <jakub@jirutka.cz>2017-05-01 00:43:19 +0200
commit41489596392977197d046ca034685664a3f4afa4 (patch)
treeef791ac83fd7635db59db40e12beb20a66ada3bd /community/rust/check-rustc
parentabfa07f26ff2837922903586b15e137b67b43219 (diff)
downloadaports-41489596392977197d046ca034685664a3f4afa4.tar.bz2
aports-41489596392977197d046ca034685664a3f4afa4.tar.xz
community/rust: move from testing
Diffstat (limited to 'community/rust/check-rustc')
-rwxr-xr-xcommunity/rust/check-rustc106
1 files changed, 106 insertions, 0 deletions
diff --git a/community/rust/check-rustc b/community/rust/check-rustc
new file mode 100755
index 0000000000..2e96a45f60
--- /dev/null
+++ b/community/rust/check-rustc
@@ -0,0 +1,106 @@
+#!/bin/sh
+# vim: set ts=4:
+set -eu
+
+RUSTC="$1"
+TMPDIR="$(pwd)/.tmp-${0##*/}-$RANDOM"
+failed=0
+
+
+_rustc() {
+ printf '\n$ rustc %s\n' "$*"
+ "$RUSTC" "$@"
+}
+
+die() {
+ printf '\033[1;31mERROR:\033[0m %s\n' "$1" >&2 # bold red
+ exit 1
+}
+
+fail() {
+ printf '\033[1;31mFAIL:\033[0m %s\n' "$1" >&2 # bold red
+ failed=$(( failed + 1 ))
+}
+
+assert_dynamic() {
+ readelf -l "$1" | grep -Fqw INTERP \
+ && readelf -d "$1" | grep -Fqw NEEDED || {
+ fail "$1 is not a dynamic executable!"
+ readelf -ld "$1"
+ }
+}
+
+assert_ok() {
+ "$1" || fail "$1 exited with status $?"
+}
+
+assert_panic() {
+ local status=0
+ "$1" || status=$? && [ "$status" = 101 ] \
+ || fail "$1 exited with status $status, but expected 101"
+}
+
+assert_pie() {
+ readelf -d "$1" | grep -Fw FLAGS_1 | grep -Fqw PIE || {
+ fail "$1 is not a PIE executable!"
+ readelf -d "$1"
+ }
+}
+
+assert_static() {
+ test -f "$1" \
+ && ! readelf -l "$1" | grep -Fqw INTERP \
+ && ! readelf -d "$1" | grep -Fqw NEEDED || {
+ fail "$1 is not a static executable!"
+ readelf -ld "$1"
+ }
+}
+
+
+#-------------------- M a i n --------------------
+
+test -d "$TMPDIR" && die "$TMPDIR already exists!"
+mkdir -p "$TMPDIR"
+trap "rm -R '$TMPDIR'" EXIT
+
+cd "$TMPDIR"
+
+cat >> hello_world.rs <<-EOF
+ fn main() {
+ println!("Hello, world!");
+ }
+EOF
+
+_rustc hello_world.rs
+assert_ok ./hello_world
+assert_dynamic hello_world
+assert_pie hello_world
+rm -f hello_world
+
+_rustc -C target-feature=-crt-static hello_world.rs
+assert_ok ./hello_world
+assert_dynamic hello_world
+assert_pie hello_world
+rm -f hello_world
+
+_rustc -C target-feature=+crt-static hello_world.rs
+assert_ok ./hello_world
+assert_static hello_world
+assert_pie hello_world
+rm -f hello_world
+
+
+cat >> panic.rs <<-EOF
+ fn main() {
+ panic!("This should panic");
+ }
+EOF
+
+_rustc -C target-feature=-crt-static panic.rs
+assert_panic ./panic
+
+_rustc -C target-feature=+crt-static panic.rs
+assert_panic ./panic
+
+
+[ "$failed" -eq 0 ] || die "$failed assertion(s) has failed"