Skip to content

Commit c103773

Browse files
committed
Improve build scripts
1 parent 09d62d0 commit c103773

File tree

14 files changed

+186
-139
lines changed

14 files changed

+186
-139
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/target/
1+
target
2+
target-docker
23
**/*.rs.bk
34
webui/.cache
45
webui/dist

ci/build.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
cd "$(dirname $(readlink -f "$0"))/.."
5+
6+
source ./ci/check_if_nightly.sh
7+
8+
cd preload
9+
cargo build --release --target=x86_64-unknown-linux-gnu $FEATURES_NIGHTLY
10+
cd ..
11+
12+
cd cli
13+
cargo build --release --target=x86_64-unknown-linux-gnu
14+
cd ..
15+
16+
cd gather
17+
cargo build --release --target=x86_64-unknown-linux-gnu
18+
cd ..

ci/build_and_package.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
cd "$(dirname $(readlink -f "$0"))/.."
5+
6+
./ci/build.sh
7+
./ci/package.sh

ci/build_for_deployment.sh

Lines changed: 0 additions & 42 deletions
This file was deleted.

ci/check_if_nightly.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
set +e
4+
echo "$(rustc --version)" | grep -q "nightly"
5+
if [ "$?" = "0" ]; then
6+
FEATURES_NIGHTLY="--features nightly"
7+
else
8+
FEATURES_NIGHTLY=""
9+
fi
10+
set -e

ci/docker/Dockerfile.hybrid

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM ubuntu:disco
1+
FROM ubuntu:focal
22
MAINTAINER Jan Bujak (j@exia.io)
33

44
RUN apt-get update && \
5-
apt-get install -y --no-install-recommends ca-certificates file gcc g++ git locales make qemu-user
5+
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends ca-certificates file gcc g++ git locales make qemu-user curl yarnpkg
66

77
RUN locale-gen en_US.UTF-8 && \
88
update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
@@ -40,5 +40,15 @@ RUN mkdir -p \
4040

4141
COPY static/cargo.config /home/user/.cargo/config
4242

43-
USER user
4443
ENV RUST_BACKTRACE=1
44+
45+
ARG USE_HOST_RUSTC=0
46+
RUN [ $USE_HOST_RUSTC -eq 1 ] || curl https://static.rust-lang.org/rustup/archive/1.24.1/x86_64-unknown-linux-gnu/rustup-init > rustup-init
47+
RUN [ $USE_HOST_RUSTC -eq 1 ] || chmod +x rustup-init
48+
RUN [ $USE_HOST_RUSTC -eq 1 ] || ./rustup-init --profile minimal --default-toolchain nightly-2021-06-08 -y
49+
RUN [ $USE_HOST_RUSTC -eq 1 ] || run-if-enabled aarch64-unknown-linux-gnu "rustup target add aarch64-unknown-linux-gnu"
50+
RUN [ $USE_HOST_RUSTC -eq 1 ] || run-if-enabled armv7-unknown-linux-gnueabihf "rustup target add armv7-unknown-linux-gnueabihf"
51+
RUN [ $USE_HOST_RUSTC -eq 1 ] || run-if-enabled mips64-unknown-linux-gnuabi64 "rustup target add mips64-unknown-linux-gnuabi64"
52+
53+
ARG CARGO_TARGET_DIR=/home/user/cwd/target-docker
54+
ENV CARGO_TARGET_DIR=$CARGO_TARGET_DIR

ci/docker/run.sh

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,35 @@
22

33
set -euo pipefail
44

5-
CWD="$(pwd)"
65
cd "$(dirname $(readlink -f "$0"))"
6+
CWD="$(pwd)/../.."
77

8-
TARGET_LIST=$(rustup target list | grep "(installed)" | cut -d " " -f 1)
98
EXTRA_ARGS=""
10-
IS_INTERACTIVE=0
119
IMAGE_TAG=crossenv
1210

11+
IS_INTERACTIVE=0
12+
TARGET_LIST="aarch64-unknown-linux-gnu armv7-unknown-linux-gnueabihf mips64-unknown-linux-gnuabi64"
13+
USE_HOST_RUSTC=0
14+
CARGO_TARGET_DIR="/home/user/cwd/target-docker"
15+
1316
set +u
14-
if [ "$1" == "--interactive" ]; then
15-
EXTRA_ARGS="$EXTRA_ARGS --entrypoint /bin/bash -v /:/mnt/host"
16-
IS_INTERACTIVE=1
17-
IMAGE_TAG=crossenv-interactive
18-
shift
19-
fi
17+
while true
18+
do
19+
if [ "$1" == "--interactive" ]; then
20+
EXTRA_ARGS="$EXTRA_ARGS --entrypoint /bin/bash -v /:/mnt/host"
21+
IS_INTERACTIVE=1
22+
IMAGE_TAG="$IMAGE_TAG-interactive"
23+
shift
24+
elif [ "$1" == "--use-host-rustc" ]; then
25+
TARGET_LIST=$(rustup target list | grep "(installed)" | cut -d " " -f 1)
26+
USE_HOST_RUSTC=1
27+
CARGO_TARGET_DIR="/home/user/cwd/target"
28+
IMAGE_TAG="$IMAGE_TAG-host-rustc"
29+
shift
30+
else
31+
break
32+
fi
33+
done
2034
set -u
2135

2236
docker build \
@@ -26,17 +40,19 @@ docker build \
2640
--build-arg UID="$(id -u)" \
2741
--build-arg GID="$(id -g)" \
2842
--build-arg IS_INTERACTIVE="$IS_INTERACTIVE" \
43+
--build-arg CARGO_TARGET_DIR="$CARGO_TARGET_DIR" \
44+
--build-arg USE_HOST_RUSTC="$USE_HOST_RUSTC" \
2945
./
3046

47+
if [ "$USE_HOST_RUSTC" == "1" ]; then
48+
EXTRA_ARGS="$EXTRA_ARGS -v $HOME/.rustup:/home/user/.rustup -v $HOME/.cargo/bin:/home/user/.cargo/bin -v $HOME/.cargo/git:/home/user/.cargo/git -v $HOME/.cargo/registry:/home/user/.cargo/registry"
49+
fi
50+
3151
docker run \
3252
--rm \
3353
--tty \
3454
--interactive \
3555
$EXTRA_ARGS \
36-
-v ~/.rustup:/home/user/.rustup \
37-
-v ~/.cargo/bin:/home/user/.cargo/bin \
38-
-v ~/.cargo/git:/home/user/.cargo/git \
39-
-v ~/.cargo/registry:/home/user/.cargo/registry \
4056
-v "$CWD:/home/user/cwd" \
4157
-w /home/user/cwd \
4258
$IMAGE_TAG \

ci/docker/static/run-if-enabled

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ set -euo pipefail
55
set +e
66
echo "$TARGET_LIST" | grep -q "$1"
77
R=$?
8+
shift
89
set -e
910

1011
if [[ "$R" == "0" ]]; then
11-
/bin/bash -c "set -euo pipefail ; $2"
12+
/bin/bash -c "set -euo pipefail ; $@"
1213
exit $?
1314
fi
1415

ci/package.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
cd "$(dirname $(readlink -f "$0"))/.."
5+
6+
CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-$(dirname $(readlink -f "$0"))/../target}
7+
8+
echo "Packaging for deployment..."
9+
10+
rm -Rf $CARGO_TARGET_DIR/travis-deployment $CARGO_TARGET_DIR/travis-deployment-tmp
11+
mkdir -p $CARGO_TARGET_DIR/travis-deployment $CARGO_TARGET_DIR/travis-deployment-tmp
12+
13+
cp $CARGO_TARGET_DIR/x86_64-unknown-linux-gnu/release/libmemory_profiler.so $CARGO_TARGET_DIR/travis-deployment-tmp/
14+
cp $CARGO_TARGET_DIR/x86_64-unknown-linux-gnu/release/memory-profiler-cli $CARGO_TARGET_DIR/travis-deployment-tmp/
15+
cp $CARGO_TARGET_DIR/x86_64-unknown-linux-gnu/release/memory-profiler-gather $CARGO_TARGET_DIR/travis-deployment-tmp/
16+
17+
cd $CARGO_TARGET_DIR/travis-deployment-tmp
18+
tar -zcf ../travis-deployment/memory-profiler-x86_64-unknown-linux-gnu.tgz \
19+
libmemory_profiler.so \
20+
memory-profiler-cli \
21+
memory-profiler-gather
22+
23+
echo "Deployment package built!"

ci/run_cross_tests.sh

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
set -euo pipefail
44
cd "$(dirname $(readlink -f "$0"))/.."
55

6-
set +e
7-
echo "$(rustc --version)" | grep -q "nightly"
8-
if [ "$?" = "0" ]; then
9-
echo "Running on nightly!"
10-
EXTRA_ARGS="--features nightly"
11-
else
12-
EXTRA_ARGS=""
13-
fi
14-
set -e
6+
source ./ci/check_if_nightly.sh
157

168
export MEMORY_PROFILER_TEST_TARGET=$1
179
export MEMORY_PROFILER_TEST_RUNNER=/usr/local/bin/runner
18-
export CARGO_TARGET_DIR="target/cross"
1910

20-
cargo build --target=$MEMORY_PROFILER_TEST_TARGET -p memory-profiler $EXTRA_ARGS
21-
MEMORY_PROFILER_TEST_PRELOAD_PATH=$MEMORY_PROFILER_TEST_TARGET/debug cargo test -p integration-tests
11+
cd preload
12+
cargo build --target=$MEMORY_PROFILER_TEST_TARGET $FEATURES_NIGHTLY
13+
cd ..
2214

23-
cargo build --target=$MEMORY_PROFILER_TEST_TARGET --release -p memory-profiler
24-
MEMORY_PROFILER_TEST_PRELOAD_PATH=$MEMORY_PROFILER_TEST_TARGET/release cargo test -p integration-tests
15+
cd integration-tests
16+
MEMORY_PROFILER_TEST_PRELOAD_PATH=$MEMORY_PROFILER_TEST_TARGET/debug cargo test --no-default-features
17+
cd ..
18+
19+
cd preload
20+
cargo build --target=$MEMORY_PROFILER_TEST_TARGET $FEATURES_NIGHTLY --release
21+
cd ..
22+
23+
cd integration-tests
24+
MEMORY_PROFILER_TEST_PRELOAD_PATH=$MEMORY_PROFILER_TEST_TARGET/release cargo test --no-default-features
25+
cd ..

0 commit comments

Comments
 (0)