2022-05-03 14:46:39 +03:00
FROM rust:1.60.0-slim-bullseye # make sure to update rust-toolchain.toml too so that everything uses the same rust version
2021-02-02 17:14:27 +03:00
WORKDIR /earthbuild
prep-debian:
RUN apt -y update
install-other-libs:
FROM +prep-debian
RUN apt -y install wget git
RUN apt -y install libxcb-shape0-dev libxcb-xfixes0-dev # for editor clipboard
2021-09-29 16:02:23 +03:00
RUN apt -y install libasound2-dev # for editor sounds
2021-08-29 23:59:43 +03:00
RUN apt -y install libunwind-dev pkg-config libx11-dev zlib1g-dev
2022-05-02 16:34:00 +03:00
RUN apt -y install unzip # for www/build.sh
2021-02-02 17:14:27 +03:00
2021-02-03 18:45:04 +03:00
install-zig-llvm-valgrind-clippy-rustfmt:
2021-02-02 17:14:27 +03:00
FROM +install-other-libs
2022-03-11 02:27:15 +03:00
# editor
RUN apt -y install libxkbcommon-dev
2021-02-03 18:45:04 +03:00
# zig
2022-02-15 08:23:42 +03:00
RUN wget -c https://ziglang.org/download/0.9.1/zig-linux-x86_64-0.9.1.tar.xz --no-check-certificate
RUN tar -xf zig-linux-x86_64-0.9.1.tar.xz
2022-05-07 20:38:04 +03:00
RUN ln -s /earthbuild/zig-linux-x86_64-0.9.1/zig /bin/zig
2022-03-11 02:27:15 +03:00
# zig builtins wasm tests
RUN apt -y install build-essential
RUN cargo install wasmer-cli --features "singlepass"
2021-02-03 18:45:04 +03:00
# llvm
2021-02-02 17:14:27 +03:00
RUN apt -y install lsb-release software-properties-common gnupg
RUN wget https://apt.llvm.org/llvm.sh
RUN chmod +x llvm.sh
2022-04-08 15:38:11 +03:00
RUN ./llvm.sh 13
RUN ln -s /usr/bin/clang-13 /usr/bin/clang
2021-02-09 13:29:41 +03:00
# use lld as linker
2022-04-08 15:38:11 +03:00
RUN ln -s /usr/bin/lld-13 /usr/bin/ld.lld
2021-02-22 00:09:17 +03:00
ENV RUSTFLAGS="-C link-arg=-fuse-ld=lld -C target-cpu=native"
2021-02-03 18:45:04 +03:00
# valgrind
2021-09-05 14:31:58 +03:00
RUN apt -y install valgrind
2021-02-03 18:45:04 +03:00
# clippy
2021-02-02 17:14:27 +03:00
RUN rustup component add clippy
2021-02-03 18:45:04 +03:00
# rustfmt
2021-02-02 17:14:27 +03:00
RUN rustup component add rustfmt
2022-03-27 12:37:34 +03:00
# wasm repl & tests
RUN rustup target add wasm32-unknown-unknown wasm32-wasi
2022-02-27 14:26:17 +03:00
RUN apt -y install libssl-dev
2022-02-27 01:45:45 +03:00
RUN OPENSSL_NO_VENDOR=1 cargo install wasm-pack
2021-05-17 20:44:03 +03:00
# criterion
2021-08-02 19:34:29 +03:00
RUN cargo install cargo-criterion
2021-02-08 20:59:21 +03:00
# sccache
2021-02-25 05:00:00 +03:00
RUN cargo install sccache
2021-02-08 22:06:32 +03:00
RUN sccache -V
2021-02-22 00:09:17 +03:00
ENV RUSTC_WRAPPER=/usr/local/cargo/bin/sccache
ENV SCCACHE_DIR=/earthbuild/sccache_dir
ENV CARGO_INCREMENTAL=0 # no need to recompile package when using new function
2021-02-05 21:48:02 +03:00
2021-02-25 05:00:00 +03:00
copy-dirs:
FROM +install-zig-llvm-valgrind-clippy-rustfmt
2022-05-09 10:48:28 +03:00
COPY --dir bindgen cli cli_utils compiler docs docs_cli editor ast code_markup error_macros highlight utils test_utils reporting repl_cli repl_eval repl_test repl_wasm repl_www roc_std vendor examples linker Cargo.toml Cargo.lock version.txt www wasi-libc-sys ./
2021-02-22 03:11:25 +03:00
2021-02-05 21:48:02 +03:00
test-zig:
FROM +install-zig-llvm-valgrind-clippy-rustfmt
COPY --dir compiler/builtins/bitcode ./
2022-03-11 02:27:15 +03:00
RUN cd bitcode && ./run-tests.sh && ./run-wasm-tests.sh
2021-02-03 21:54:25 +03:00
2022-05-04 15:00:39 +03:00
build-rust-test:
2021-08-24 13:34:22 +03:00
FROM +copy-dirs
2022-05-04 15:00:39 +03:00
RUN --mount=type=cache,target=$SCCACHE_DIR \
cargo test --locked --release --features with_sound --workspace --no-run && sccache --show-stats
check-clippy:
FROM +build-rust-test
2021-02-09 13:29:41 +03:00
RUN cargo clippy -V
2021-02-22 00:09:17 +03:00
RUN --mount=type=cache,target=$SCCACHE_DIR \
2022-05-16 04:59:52 +03:00
cargo clippy --workspace --tests -- --deny warnings
RUN --mount=type=cache,target=$SCCACHE_DIR \
cargo clippy --workspace --tests --release -- --deny warnings
2021-02-05 22:34:53 +03:00
check-rustfmt:
2022-05-04 15:00:39 +03:00
FROM +build-rust-test
2021-02-09 13:29:41 +03:00
RUN cargo fmt --version
2021-02-05 22:34:53 +03:00
RUN cargo fmt --all -- --check
2021-06-05 21:02:54 +03:00
check-typos:
2021-07-12 20:31:07 +03:00
RUN cargo install typos-cli --version 1.0.11 # version set to prevent confusion if the version is updated automatically
2022-03-08 17:43:04 +03:00
COPY --dir .github ci cli cli_utils compiler docs editor examples ast code_markup highlight utils linker nightly_benches packages roc_std www *.md LEGAL_DETAILS shell.nix version.txt ./
2021-06-05 21:02:54 +03:00
RUN typos
2021-02-03 21:54:25 +03:00
test-rust:
2022-05-04 15:00:39 +03:00
FROM +build-rust-test
2022-05-18 23:12:29 +03:00
ENV ROC_WORKSPACE_DIR=/earthbuild
2021-02-22 00:09:17 +03:00
ENV RUST_BACKTRACE=1
2021-10-23 20:53:39 +03:00
# for race condition problem with cli test
ENV ROC_NUM_WORKERS=1
2021-08-31 13:48:50 +03:00
# run one of the benchmarks to make sure the host is compiled
# not pre-compiling the host can cause race conditions
RUN echo "4" | cargo run --release examples/benchmarks/NQueens.roc
2021-02-22 00:09:17 +03:00
RUN --mount=type=cache,target=$SCCACHE_DIR \
2021-11-20 12:22:26 +03:00
cargo test --locked --release --features with_sound --workspace && sccache --show-stats
2021-11-09 06:55:17 +03:00
# test the dev and wasm backend: they require an explicit feature flag.
2021-11-07 17:50:22 +03:00
RUN --mount=type=cache,target=$SCCACHE_DIR \
2021-11-20 12:22:26 +03:00
cargo test --locked --release --package test_gen --no-default-features --features gen-dev && sccache --show-stats
2021-11-09 06:41:31 +03:00
# gen-wasm has some multithreading problems to do with the wasmer runtime. Run it single-threaded as a separate job
RUN --mount=type=cache,target=$SCCACHE_DIR \
2021-11-20 12:22:26 +03:00
cargo test --locked --release --package test_gen --no-default-features --features gen-wasm -- --test-threads=1 && sccache --show-stats
2022-02-27 14:26:17 +03:00
# repl_test: build the compiler for wasm target, then run the tests on native target
2021-09-04 14:55:22 +03:00
RUN --mount=type=cache,target=$SCCACHE_DIR \
2022-02-27 20:03:39 +03:00
repl_test/test_wasm.sh && sccache --show-stats
2021-09-04 14:55:22 +03:00
# run i386 (32-bit linux) cli tests
2022-03-31 00:57:48 +03:00
# NOTE: disabled until zig 0.9
# RUN echo "4" | cargo run --locked --release --features="target-x86" -- --target=x86_32 examples/benchmarks/NQueens.roc
# RUN --mount=type=cache,target=$SCCACHE_DIR \
# cargo test --locked --release --features with_sound --test cli_run i386 --features="i386-cli-run" && sccache --show-stats
2022-05-15 17:47:25 +03:00
# make sure website deployment works (that is, make sure build.sh returns status code 0)
2022-05-16 11:02:43 +03:00
ENV REPL_DEBUG=1
2022-05-02 03:57:18 +03:00
RUN bash www/build.sh
2021-02-05 21:48:02 +03:00
2021-06-08 04:26:10 +03:00
verify-no-git-changes:
FROM +test-rust
# If running tests caused anything to be changed or added (without being
# included in a .gitignore somewhere), fail the build!
#
# How it works: the `git ls-files` command lists all the modified or
# uncommitted files in the working tree, the `| grep -E .` command returns a
# zero exit code if it listed any files and nonzero otherwise (which is the
# opposite of what we want), and the `!` at the start inverts the exit code.
RUN ! git ls-files --deleted --modified --others --exclude-standard | grep -E .
2021-02-05 21:48:02 +03:00
test-all:
BUILD +test-zig
2021-02-22 00:09:17 +03:00
BUILD +check-rustfmt
BUILD +check-clippy
2021-02-05 21:48:02 +03:00
BUILD +test-rust
2021-06-08 04:26:10 +03:00
BUILD +verify-no-git-changes
2021-05-17 20:44:03 +03:00
2021-10-22 20:42:41 +03:00
build-nightly-release:
2021-10-23 20:53:39 +03:00
FROM +test-rust
2021-11-09 19:25:18 +03:00
COPY --dir .git LICENSE LEGAL_DETAILS ./
2021-10-26 17:43:03 +03:00
# version.txt is used by the CLI: roc --version
2021-10-23 20:53:39 +03:00
RUN printf "nightly pre-release, built from commit " > version.txt
RUN git log --pretty=format:'%h' -n 1 >> version.txt
2021-11-09 19:25:18 +03:00
RUN printf " on: " >> version.txt
RUN date >> version.txt
2021-12-05 13:40:19 +03:00
RUN RUSTFLAGS="-C target-cpu=x86-64" cargo build --features with_sound --release
2022-02-26 09:47:12 +03:00
RUN cd ./target/release && tar -czvf roc_linux_x86_64.tar.gz ./roc ../../LICENSE ../../LEGAL_DETAILS ../../examples/hello-world ../../compiler/builtins/bitcode/src/ ../../roc_std
2021-10-23 20:53:39 +03:00
SAVE ARTIFACT ./target/release/roc_linux_x86_64.tar.gz AS LOCAL roc_linux_x86_64.tar.gz
2021-10-22 20:42:41 +03:00
2021-10-03 18:26:11 +03:00
# compile everything needed for benchmarks and output a self-contained dir from which benchmarks can be run.
2021-06-09 19:52:34 +03:00
prep-bench-folder:
2021-08-24 13:34:22 +03:00
FROM +copy-dirs
2021-06-09 19:52:34 +03:00
ARG BENCH_SUFFIX=branch
2021-05-17 20:44:03 +03:00
RUN cargo criterion -V
2021-06-09 19:52:34 +03:00
RUN --mount=type=cache,target=$SCCACHE_DIR cd cli && cargo criterion --no-run
RUN mkdir -p bench-folder/compiler/builtins/bitcode/src
RUN mkdir -p bench-folder/target/release/deps
RUN mkdir -p bench-folder/examples/benchmarks
RUN cp examples/benchmarks/*.roc bench-folder/examples/benchmarks/
RUN cp -r examples/benchmarks/platform bench-folder/examples/benchmarks/
RUN cp compiler/builtins/bitcode/src/str.zig bench-folder/compiler/builtins/bitcode/src
RUN cp target/release/roc bench-folder/target/release
# copy the most recent time bench to bench-folder
RUN cp target/release/deps/`ls -t target/release/deps/ | grep time_bench | head -n 1` bench-folder/target/release/deps/time_bench
SAVE ARTIFACT bench-folder AS LOCAL bench-folder-$BENCH_SUFFIX