Skip to content

Commit 8691b8b

Browse files
committed
Test rust-lang/regex example shootout-regex-dna
1 parent ee4927e commit 8691b8b

File tree

8 files changed

+92
-23
lines changed

8 files changed

+92
-23
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ perf.data.old
88
/build_sysroot/sysroot_src
99
/build_sysroot/Cargo.lock
1010
/rust
11+
/regex

build_sysroot/build_sysroot.sh

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
11
#!/bin/bash
2+
3+
# Requires the CHANNEL env var to be set to `debug` or `release.`
4+
25
set -e
36
cd $(dirname "$0")
47

8+
pushd ../ >/dev/null
9+
source ./config.sh
10+
popd >/dev/null
11+
512
# Cleanup for previous run
613
# v Clean target dir except for build scripts and incremental cache
714
rm -r target/*/{debug,release}/{build,deps,examples,libsysroot*,native} || true
815
rm Cargo.lock 2>/dev/null || true
916
rm -r sysroot 2>/dev/null || true
1017

11-
# FIXME find a better way to get the target triple
12-
unamestr=`uname`
13-
if [[ "$unamestr" == 'Linux' ]]; then
14-
TARGET_TRIPLE='x86_64-unknown-linux-gnu'
15-
elif [[ "$unamestr" == 'Darwin' ]]; then
16-
TARGET_TRIPLE='x86_64-apple-darwin'
17-
else
18-
echo "Unsupported os"
19-
exit 1
20-
fi
21-
2218
# Build libs
23-
mkdir -p sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
2419
export RUSTFLAGS="$RUSTFLAGS -Z force-unstable-if-unmarked"
2520
if [[ "$1" == "--release" ]]; then
26-
channel='release'
21+
sysroot_channel='release'
2722
RUSTFLAGS="$RUSTFLAGS -Zmir-opt-level=3" cargo build --target $TARGET_TRIPLE --release
2823
else
29-
channel='debug'
24+
sysroot_channel='debug'
3025
cargo build --target $TARGET_TRIPLE
3126
fi
3227

3328
# Copy files to sysroot
34-
cp target/$TARGET_TRIPLE/$channel/deps/*.rlib sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
29+
mkdir -p sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
30+
cp target/$TARGET_TRIPLE/$sysroot_channel/deps/*.rlib sysroot/lib/rustlib/$TARGET_TRIPLE/lib/

cargo.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
if [ -z $CHANNEL ]; then
4+
export CHANNEL='debug'
5+
fi
6+
7+
pushd $(dirname "$0") >/dev/null
8+
source config.sh
9+
popd >/dev/null
10+
11+
cmd=$1
12+
shift
13+
14+
cargo $cmd --target $TARGET_TRIPLE $@

clean_all.sh

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
set -e
33

44
rm -rf target/ build_sysroot/{sysroot/,sysroot_src/,target/,Cargo.lock} perf.data{,.old}
5+
rm -rf regex/

config.sh

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,8 @@ else
1010
exit 1
1111
fi
1212

13-
if [[ "$1" == "--release" ]]; then
14-
channel='release'
15-
cargo build --release
16-
else
17-
channel='debug'
18-
cargo build
19-
fi
13+
TARGET_TRIPLE=$(rustc -vV | grep host | cut -d: -f2 | tr -d " ")
2014

21-
export RUSTFLAGS='-Zalways-encode-mir -Cpanic=abort -Cdebuginfo=2 -Zcodegen-backend='$(pwd)'/target/'$channel'/librustc_codegen_cranelift.'$dylib_ext' --sysroot '$(pwd)'/build_sysroot/sysroot'
15+
export RUSTFLAGS='-Zalways-encode-mir -Cpanic=abort -Cdebuginfo=2 -Zcodegen-backend='$(pwd)'/target/'$CHANNEL'/librustc_codegen_cranelift.'$dylib_ext' --sysroot '$(pwd)'/build_sysroot/sysroot'
2216
RUSTC="rustc $RUSTFLAGS -L crate=target/out --out-dir target/out"
2317
export RUSTC_LOG=warn # display metadata load errors

crate_patches/regex.patch

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
From febff2a8c639efb5de1e1b4758cdb473847d80ce Mon Sep 17 00:00:00 2001
2+
From: bjorn3 <[email protected]>
3+
Date: Tue, 30 Jul 2019 12:12:37 +0200
4+
Subject: [PATCH] Disable threads in shootout-regex-dna example
5+
6+
---
7+
examples/shootout-regex-dna.rs | 4 ++--
8+
1 file changed, 2 insertions(+), 2 deletions(-)
9+
10+
diff --git a/examples/shootout-regex-dna.rs b/examples/shootout-regex-dna.rs
11+
index 2171bb3..37382f8 100644
12+
--- a/examples/shootout-regex-dna.rs
13+
+++ b/examples/shootout-regex-dna.rs
14+
@@ -37,7 +37,7 @@ fn main() {
15+
for variant in variants {
16+
let seq = seq_arc.clone();
17+
let restr = variant.to_string();
18+
- let future = thread::spawn(move || variant.find_iter(&seq).count());
19+
+ let future = variant.find_iter(&seq).count();
20+
counts.push((restr, future));
21+
}
22+
23+
@@ -60,7 +60,7 @@ fn main() {
24+
}
25+
26+
for (variant, count) in counts {
27+
- println!("{} {}", variant, count.join().unwrap());
28+
+ println!("{} {}", variant, count);
29+
}
30+
println!("\n{}\n{}\n{}", ilen, clen, seq.len());
31+
}
32+
--
33+
2.11.0
34+

prepare.sh

+7
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ set -e
44
rustup component add rust-src
55
./build_sysroot/prepare_sysroot_src.sh
66
cargo install hyperfine || echo "Skipping hyperfine install"
7+
8+
git clone https://github.com/rust-lang/regex.git || echo "rust-lang/regex has already been cloned"
9+
pushd regex
10+
git checkout -- .
11+
git checkout 341f207c1071f7290e3f228c710817c280c8dca1
12+
git apply ../crate_patches/regex.patch
13+
popd

test.sh

+22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
#!/bin/bash
2+
3+
if [[ "$1" == "--release" ]]; then
4+
export CHANNEL='release'
5+
cargo build --release
6+
else
7+
export CHANNEL='debug'
8+
cargo build
9+
fi
10+
211
source config.sh
312

413
rm -r target/out || true
@@ -39,6 +48,19 @@ $RUSTC example/mod_bench.rs --crate-type bin
3948
#echo "[BUILD] sysroot in release mode"
4049
#./build_sysroot/build_sysroot.sh --release
4150

51+
pushd regex
52+
echo "[TEST] rust-lang/regex example shootout-regex-dna"
53+
../cargo.sh clean
54+
# Make sure `[codegen mono items] start` doesn't poison the diff
55+
../cargo.sh build --example shootout-regex-dna
56+
cat examples/regexdna-input.txt | ../cargo.sh run --example shootout-regex-dna > res.txt
57+
diff -u res.txt examples/regexdna-output.txt
58+
59+
# FIXME compile libtest
60+
# echo "[TEST] rust-lang/regex standalone tests"
61+
# ../cargo.sh test
62+
popd
63+
4264
COMPILE_MOD_BENCH_INLINE="$RUSTC example/mod_bench.rs --crate-type bin -Zmir-opt-level=3 -O --crate-name mod_bench_inline"
4365
COMPILE_MOD_BENCH_LLVM_0="rustc example/mod_bench.rs --crate-type bin -Copt-level=0 -o target/out/mod_bench_llvm_0 -Cpanic=abort"
4466
COMPILE_MOD_BENCH_LLVM_1="rustc example/mod_bench.rs --crate-type bin -Copt-level=1 -o target/out/mod_bench_llvm_1 -Cpanic=abort"

0 commit comments

Comments
 (0)