Skip to content

Commit

Permalink
Simplify rust project setup. (#3830)
Browse files Browse the repository at this point in the history
* Simplify rust project setup.

- Add rust and cargo-fuzz in base builder.
- Set RUSTC_BOOSTRAP to make ASan available.
- Set RUSTFLAGS and C,CXXFLAGS properly.
  • Loading branch information
inferno-chromium authored May 17, 2020
1 parent 261abce commit 4f7cf1b
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 29 deletions.
21 changes: 15 additions & 6 deletions infra/base-images/base-builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
################################################################################

FROM gcr.io/oss-fuzz-base/base-clang
RUN apt-get install -y git \
subversion \
RUN apt-get update && apt-get install -y \
binutils-dev \
curl \
git \
jq \
python3 \
zip \
libc6-dev-i386 \
make \
binutils-dev \
libc6-dev-i386
python3 \
subversion \
zip

# Download and install the latest stable Go.
ADD https://storage.googleapis.com/golang/getgo/installer_linux $SRC/
Expand All @@ -41,6 +43,13 @@ ENV PATH $PATH:/root/.go/bin:$GOPATH/bin
RUN go get -u github.com/mdempsky/go114-fuzz-build && \
ln -s $GOPATH/bin/go114-fuzz-build $GOPATH/bin/go-fuzz

# Install Rust and cargo-fuzz for libFuzzer instrumentation.
ENV CARGO_HOME=/rust
ENV RUSTUP_HOME=/rust/rustup
ENV PATH=$PATH:/rust/bin
RUN curl https://sh.rustup.rs | sh -s -- -y --default-toolchain=nightly
RUN cargo install cargo-fuzz

# Default build flags for various sanitizers.
ENV SANITIZER_FLAGS_address "-fsanitize=address -fsanitize-address-use-after-scope"

Expand Down
20 changes: 18 additions & 2 deletions infra/base-images/base-builder/compile
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,24 @@ if [ $FUZZING_ENGINE = "none" ]; then
export COVERAGE_FLAGS=
fi

export CFLAGS="$CFLAGS $SANITIZER_FLAGS $COVERAGE_FLAGS"
export CXXFLAGS="$CFLAGS $CXXFLAGS_EXTRA"
if [[ $FUZZING_LANGUAGE == "rust" ]]; then
# Rust does not support sanitizers and coverage flags via CFLAGS/CXXFLAGS.
# Instead, use RUSTFLAGS.
# FIXME: Support code coverage once support is in.
# See https://github.com/rust-lang/rust/issues/34701.
export RUSTFLAGS="--cfg fuzzing -Zsanitizer=${SANITIZER} -Cdebuginfo=1 -Cforce-frame-pointers"

# Add Rust libfuzzer flags.
# See https://github.com/rust-fuzz/libfuzzer/blob/master/build.rs#L12.
export CUSTOM_LIBFUZZER_PATH="$LIB_FUZZING_ENGINE_DEPRECATED"
export CUSTOM_LIBFUZZER_STD_CXX=c++

# Set RUSTC_BOOTSTRAP to get nightly features like sanitizers.
export RUSTC_BOOTSTRAP=1
else
export CFLAGS="$CFLAGS $SANITIZER_FLAGS $COVERAGE_FLAGS"
export CXXFLAGS="$CFLAGS $CXXFLAGS_EXTRA"
fi

echo "CC=$CC"
echo "CXX=$CXX"
Expand Down
2 changes: 0 additions & 2 deletions projects/ecc-diff-fuzzer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
FROM gcr.io/oss-fuzz-base/base-builder
MAINTAINER p.antoine@catenacyber.fr
RUN apt-get update && apt-get install -y make cmake bzip2 autoconf automake gettext libtool python nodejs npm
ENV CARGO_HOME=/rust RUSTUP_HOME=/rust/rustup PATH=$PATH:/rust/bin
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
RUN rustup target add i686-unknown-linux-gnu
RUN npm install -g browserify
RUN npm install elliptic
Expand Down
4 changes: 0 additions & 4 deletions projects/libra/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ MAINTAINER davidwg@fb.com
# install other tools we might need
RUN apt-get update && apt-get install -y cmake curl

# install rust and cargo-fuzz
ENV CARGO_HOME=/rust RUSTUP_HOME=/rust/rustup PATH=$PATH:/rust/bin
RUN curl https://sh.rustup.rs | sh -s -- -y

# get libra
RUN git clone --depth 1 https://github.com/libra/libra $SRC/libra
WORKDIR $SRC/libra
Expand Down
3 changes: 0 additions & 3 deletions projects/libra/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ export CUSTOM_LIBFUZZER_PATH="$LIB_FUZZING_ENGINE_DEPRECATED"
export CUSTOM_LIBFUZZER_STD_CXX=c++
# export CUSTOM_LIBFUZZER_STD_CXX=none

# RUSTC_BOOTSTRAP: to get some nightly features like ASAN
export RUSTC_BOOTSTRAP=1

# export fuzzing flags
RUSTFLAGS="$RUSTFLAGS --cfg fuzzing" # used to change code logic
RUSTFLAGS="$RUSTFLAGS -Cdebug-assertions" # to get debug_assert in rust
Expand Down
4 changes: 0 additions & 4 deletions projects/mp4parse-rust/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ FROM gcr.io/oss-fuzz-base/base-builder
MAINTAINER mgregan@mozilla.com
RUN apt-get update && apt-get install -y make autoconf automake libtool curl cmake python llvm-dev libclang-dev clang

ENV CARGO_HOME=/rust RUSTUP_HOME=/rust/rustup PATH=$PATH:/rust/bin
RUN curl https://sh.rustup.rs | sh -s -- -y --default-toolchain=nightly
RUN cargo install cargo-fuzz

RUN git clone --depth 1 https://github.com/mozilla/mp4parse-rust mp4parse-rust
WORKDIR mp4parse-rust

Expand Down
4 changes: 0 additions & 4 deletions projects/serde_json/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ FROM gcr.io/oss-fuzz-base/base-builder
MAINTAINER david@adalogics.com
RUN apt-get update && apt-get install -y make autoconf automake libtool curl cmake python llvm-dev libclang-dev clang

ENV CARGO_HOME=/rust RUSTUP_HOME=/rust/rustup PATH=$PATH:/rust/bin
RUN curl https://sh.rustup.rs | sh -s -- -y --default-toolchain=nightly
RUN cargo install cargo-fuzz

RUN git clone --depth 1 https://github.com/serde-rs/json json
WORKDIR $SRC

Expand Down
4 changes: 0 additions & 4 deletions projects/wasmtime/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ FROM gcr.io/oss-fuzz-base/base-builder
MAINTAINER foote@fastly.com
RUN apt-get update && apt-get install -y make autoconf automake libtool curl cmake python llvm-dev libclang-dev clang

ENV CARGO_HOME=/rust RUSTUP_HOME=/rust/rustup PATH=$PATH:/rust/bin
RUN curl https://sh.rustup.rs | sh -s -- -y --default-toolchain=nightly
RUN cargo install cargo-fuzz

RUN git clone --depth 1 https://github.com/bytecodealliance/wasmtime wasmtime
WORKDIR wasmtime
RUN git submodule update --init --recursive
Expand Down

0 comments on commit 4f7cf1b

Please # to comment.