Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set rust flags always in compile step. #3859

Merged
merged 1 commit into from
May 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions infra/base-images/base-builder/compile
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,28 @@ if [ $FUZZING_ENGINE = "none" ]; then
export COVERAGE_FLAGS=
fi

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
# Rust does not support sanitizers and coverage flags via CFLAGS/CXXFLAGS, so
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I would, if possible, recommend disabling this. Fuzzing currently will require the nightly channel of Rust, but I don't think it's worthwhile to support fuzzing on the "stable" channel via this flag since it's not really stable once this is enabled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we always use nightly - https://github.com/google/oss-fuzz/blob/master/infra/base-images/base-builder/Dockerfile#L50
Is this flag not needed for nightly ? Sorry i am confused what this flag does, i thought sanitizers wont work in nightly without this flag.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah if the nightly channel is always used then this flag isn't necessary. This flag is a "hack" which enables nightly features on all compilers, regardless of channel. If you want to use sanitizers, which require an unstable -Z flag, on the stable channel then this is the only way. It's not generally recommended to use this flag, however, and if you're using the nightly channel it's not necessary to use the flag.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok removed in 286badc


export CFLAGS="$CFLAGS $SANITIZER_FLAGS $COVERAGE_FLAGS"
export CXXFLAGS="$CFLAGS $CXXFLAGS_EXTRA"

echo "---------------------------------------------------------------"
echo "CC=$CC"
echo "CXX=$CXX"
echo "CFLAGS=$CFLAGS"
echo "CXXFLAGS=$CXXFLAGS"

echo "---------------------------------------------------------------"

BUILD_CMD="bash -eux $SRC/build.sh"
Expand Down