Skip to content

Commit

Permalink
feat: support build with sanitizers (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbaliasnikov authored Jun 18, 2024
1 parent 51b3bf9 commit c75308c
Show file tree
Hide file tree
Showing 20 changed files with 178 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/actions/build_and_test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ runs:
LIBSTDCPP_SOURCE_PATH: "C:/a/_temp/msys64/mingw64/lib/libstdc++.a"
run: |
cargo install cargo2junit
[ "${RUNNER_OS}" = "Windows" ] && ADD_FLAGS="--skip debug_build_with_tests_coverage"
[ "${RUNNER_OS}" = "Windows" ] && ADD_FLAGS="--skip debug_build_with_tests_coverage --skip build_with_sanitizers"
cargo test --no-fail-fast -- ${ADD_FLAGS} -Z unstable-options --format json \
| cargo2junit | tee "${UNIT_TESTS_RESULTS_XML}"
Expand Down
30 changes: 0 additions & 30 deletions .github/actions/prepare-msys/action.yml

This file was deleted.

13 changes: 12 additions & 1 deletion .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ concurrency:
cancel-in-progress: true

jobs:

# Check for cargo licensing issues
cargo-license:
uses: matter-labs/era-compiler-ci/.github/workflows/cargo-license.yaml@v1
secrets: inherit

# Check for secrets leak in the repository
secrets-scanner:
uses: matter-labs/era-compiler-ci/.github/workflows/secrets-scanner.yaml@v1
secrets: inherit

check-formatting:
name: Check formatting
runs-on: ubuntu-latest
Expand Down Expand Up @@ -56,7 +67,7 @@ jobs:

- name: Prepare Windows env
if: runner.os == 'Windows'
uses: ./.github/actions/prepare-msys
uses: matter-labs/era-compiler-ci/.github/actions/prepare-msys@v1

- name: Prepare MacOS environment
shell: bash
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/cargo-license.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions .github/workflows/secrets_scanner.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "compiler-llvm-builder"
version = "1.0.25"
version = "1.0.26"
authors = [
"Oleksandr Zarudnyi <a.zarudnyy@matterlabs.dev>",
"Anton Baliasnikov <aba@matterlabs.dev>",
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod build_type;
pub mod llvm_path;
pub mod lock;
pub mod platforms;
pub mod sanitizer;
pub mod utils;

pub use self::build_type::BuildType;
Expand Down Expand Up @@ -150,6 +151,7 @@ pub fn build(
extra_args: Vec<String>,
use_ccache: bool,
enable_assertions: bool,
sanitizer: Option<sanitizer::Sanitizer>,
) -> anyhow::Result<()> {
std::fs::create_dir_all(LLVMPath::DIRECTORY_LLVM_TARGET)?;

Expand All @@ -164,6 +166,7 @@ pub fn build(
extra_args,
use_ccache,
enable_assertions,
sanitizer,
)?;
} else if target_env == platforms::TargetEnv::GNU {
platforms::x86_64_linux_gnu::build(
Expand All @@ -174,6 +177,7 @@ pub fn build(
extra_args,
use_ccache,
enable_assertions,
sanitizer,
)?;
} else {
anyhow::bail!("Unsupported target environment for x86_64 and Linux");
Expand All @@ -187,6 +191,7 @@ pub fn build(
extra_args,
use_ccache,
enable_assertions,
sanitizer,
)?;
} else if cfg!(target_os = "windows") && cfg!(target_env = "gnu") {
platforms::x86_64_windows_gnu::build(
Expand All @@ -197,6 +202,7 @@ pub fn build(
extra_args,
use_ccache,
enable_assertions,
sanitizer,
)?;
} else {
anyhow::bail!("Unsupported target OS for x86_64");
Expand All @@ -212,6 +218,7 @@ pub fn build(
extra_args,
use_ccache,
enable_assertions,
sanitizer,
)?;
} else if target_env == platforms::TargetEnv::GNU {
platforms::aarch64_linux_gnu::build(
Expand All @@ -222,6 +229,7 @@ pub fn build(
extra_args,
use_ccache,
enable_assertions,
sanitizer,
)?;
} else {
anyhow::bail!("Unsupported target environment for aarch64 and Linux");
Expand All @@ -235,6 +243,7 @@ pub fn build(
extra_args,
use_ccache,
enable_assertions,
sanitizer,
)?;
} else {
anyhow::bail!("Unsupported target OS for aarch64");
Expand Down
6 changes: 6 additions & 0 deletions src/platforms/aarch64_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ use std::process::Command;
use crate::build_type::BuildType;
use crate::llvm_path::LLVMPath;
use crate::platforms::Platform;
use crate::sanitizer::Sanitizer;

///
/// The building sequence.
///
#[allow(clippy::too_many_arguments)]
pub fn build(
build_type: BuildType,
targets: HashSet<Platform>,
Expand All @@ -20,6 +22,7 @@ pub fn build(
extra_args: Vec<String>,
use_ccache: bool,
enable_assertions: bool,
sanitizer: Option<Sanitizer>,
) -> anyhow::Result<()> {
crate::utils::check_presence("cmake")?;
crate::utils::check_presence("clang")?;
Expand Down Expand Up @@ -74,6 +77,9 @@ pub fn build(
))
.args(crate::platforms::shared::shared_build_opts_assertions(
enable_assertions,
))
.args(crate::platforms::shared::shared_build_opts_sanitizers(
sanitizer,
)),
"LLVM building cmake",
)?;
Expand Down
8 changes: 8 additions & 0 deletions src/platforms/aarch64_linux_musl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ use std::process::Command;
use crate::build_type::BuildType;
use crate::llvm_path::LLVMPath;
use crate::platforms::Platform;
use crate::sanitizer::Sanitizer;

///
/// The building sequence.
///
#[allow(clippy::too_many_arguments)]
pub fn build(
build_type: BuildType,
targets: HashSet<Platform>,
Expand All @@ -21,6 +23,7 @@ pub fn build(
extra_args: Vec<String>,
use_ccache: bool,
enable_assertions: bool,
sanitizer: Option<Sanitizer>,
) -> anyhow::Result<()> {
crate::utils::check_presence("cmake")?;
crate::utils::check_presence("clang")?;
Expand Down Expand Up @@ -76,6 +79,7 @@ pub fn build(
extra_args,
use_ccache,
enable_assertions,
sanitizer,
)?;

Ok(())
Expand Down Expand Up @@ -262,6 +266,7 @@ fn build_target(
extra_args: Vec<String>,
use_ccache: bool,
enable_assertions: bool,
sanitizer: Option<Sanitizer>,
) -> anyhow::Result<()> {
let mut clang_path = host_target_directory.to_path_buf();
clang_path.push("bin/clang");
Expand Down Expand Up @@ -320,6 +325,9 @@ fn build_target(
))
.args(crate::platforms::shared::shared_build_opts_assertions(
enable_assertions,
))
.args(crate::platforms::shared::shared_build_opts_sanitizers(
sanitizer,
)),
"LLVM target building cmake",
)?;
Expand Down
8 changes: 7 additions & 1 deletion src/platforms/aarch64_macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ use std::process::Command;
use crate::build_type::BuildType;
use crate::llvm_path::LLVMPath;
use crate::platforms::Platform;
use crate::sanitizer::Sanitizer;

///
/// The building sequence.
///
#[allow(clippy::too_many_arguments)]
pub fn build(
build_type: BuildType,
targets: HashSet<Platform>,
Expand All @@ -20,6 +22,7 @@ pub fn build(
extra_args: Vec<String>,
use_ccache: bool,
enable_assertions: bool,
sanitizer: Option<Sanitizer>,
) -> anyhow::Result<()> {
crate::utils::check_presence("cmake")?;
crate::utils::check_presence("ninja")?;
Expand Down Expand Up @@ -70,7 +73,10 @@ pub fn build(
.args(crate::platforms::shared::shared_build_opts_assertions(
enable_assertions,
))
.args(crate::platforms::shared::macos_build_opts_ignore_dupicate_libs_warnings()),
.args(crate::platforms::shared::macos_build_opts_ignore_dupicate_libs_warnings())
.args(crate::platforms::shared::shared_build_opts_sanitizers(
sanitizer,
)),
"LLVM building cmake",
)?;

Expand Down
11 changes: 11 additions & 0 deletions src/platforms/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! The shared options for building various platforms.
//!
use crate::sanitizer::Sanitizer;
use std::path::Path;
use std::process::Command;

Expand Down Expand Up @@ -116,6 +117,16 @@ pub fn shared_build_opts_assertions(enabled: bool) -> Vec<String> {
)]
}

///
/// The build options to enable sanitizers.
///
pub fn shared_build_opts_sanitizers(sanitizer: Option<Sanitizer>) -> Vec<String> {
match sanitizer {
Some(sanitizer) => vec![format!("-DLLVM_USE_SANITIZER='{}'", sanitizer)],
None => vec![],
}
}

///
/// The LLVM tests build options shared by all platforms.
///
Expand Down
6 changes: 6 additions & 0 deletions src/platforms/x86_64_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ use std::process::Command;
use crate::build_type::BuildType;
use crate::llvm_path::LLVMPath;
use crate::platforms::Platform;
use crate::sanitizer::Sanitizer;

///
/// The building sequence.
///
#[allow(clippy::too_many_arguments)]
pub fn build(
build_type: BuildType,
targets: HashSet<Platform>,
Expand All @@ -20,6 +22,7 @@ pub fn build(
extra_args: Vec<String>,
use_ccache: bool,
enable_assertions: bool,
sanitizer: Option<Sanitizer>,
) -> anyhow::Result<()> {
crate::utils::check_presence("cmake")?;
crate::utils::check_presence("clang")?;
Expand Down Expand Up @@ -74,6 +77,9 @@ pub fn build(
.args(extra_args)
.args(crate::platforms::shared::shared_build_opts_assertions(
enable_assertions,
))
.args(crate::platforms::shared::shared_build_opts_sanitizers(
sanitizer,
)),
"LLVM building cmake",
)?;
Expand Down
8 changes: 8 additions & 0 deletions src/platforms/x86_64_linux_musl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ use std::process::Command;
use crate::build_type::BuildType;
use crate::llvm_path::LLVMPath;
use crate::platforms::Platform;
use crate::sanitizer::Sanitizer;

///
/// The building sequence.
///
#[allow(clippy::too_many_arguments)]
pub fn build(
build_type: BuildType,
targets: HashSet<Platform>,
Expand All @@ -21,6 +23,7 @@ pub fn build(
extra_args: Vec<String>,
use_ccache: bool,
enable_assertions: bool,
sanitizer: Option<Sanitizer>,
) -> anyhow::Result<()> {
crate::utils::check_presence("cmake")?;
crate::utils::check_presence("clang")?;
Expand Down Expand Up @@ -76,6 +79,7 @@ pub fn build(
extra_args,
use_ccache,
enable_assertions,
sanitizer,
)?;

Ok(())
Expand Down Expand Up @@ -261,6 +265,7 @@ fn build_target(
extra_args: Vec<String>,
use_ccache: bool,
enable_assertions: bool,
sanitizer: Option<Sanitizer>,
) -> anyhow::Result<()> {
let mut clang_path = host_target_directory.to_path_buf();
clang_path.push("bin/clang");
Expand Down Expand Up @@ -319,6 +324,9 @@ fn build_target(
))
.args(crate::platforms::shared::shared_build_opts_assertions(
enable_assertions,
))
.args(crate::platforms::shared::shared_build_opts_sanitizers(
sanitizer,
)),
"LLVM target building cmake",
)?;
Expand Down
Loading

0 comments on commit c75308c

Please sign in to comment.