Skip to content

Commit

Permalink
ci: Enable ASan on libjxl
Browse files Browse the repository at this point in the history
  • Loading branch information
inflation committed Dec 17, 2024
1 parent fcb1707 commit 88927fa
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 69 deletions.
55 changes: 15 additions & 40 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: macos-13
rustflags: "-Clink-args=-fapple-link-rtlib"
# rustflags: "-Clink-args=-fapple-link-rtlib"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -31,18 +31,13 @@ jobs:
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest
- name: Dependency
run: cargo fetch
- uses: actions/cache@v4
id: cache
- uses: Leafwing-Studios/cargo-cache@v2
with:
path: |
target/
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
sweep-cache: true
- name: Tests
run: cargo nextest run --all-features --workspace
env:
RUSTFLAGS: "${{ matrix.rustflags }}"
# env:
# RUSTFLAGS: "${{ matrix.rustflags }}"

coverage:
name: Code Coverage
Expand All @@ -60,14 +55,9 @@ jobs:
uses: taiki-e/install-action@cargo-llvm-cov
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest
- name: Dependency
run: cargo fetch
- uses: actions/cache@v4
id: cache
- uses: Leafwing-Studios/cargo-cache@v2
with:
path: |
target/
key: ${{ runner.os }}-cargo-cov-${{ hashFiles('**/Cargo.lock') }}
sweep-cache: true
- name: Generate code coverage
run: cargo +nightly llvm-cov nextest
--all-features --workspace
Expand Down Expand Up @@ -98,35 +88,25 @@ jobs:
components: rust-src
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest
- name: Dependency
run: cargo fetch
- uses: actions/cache@v4
id: cache
- uses: Leafwing-Studios/cargo-cache@v2
with:
path: |
target/
key: ${{ runner.os }}-cargo-sanitizer-${{ hashFiles('**/Cargo.lock') }}
sweep-cache: true
- name: Test with Sanitizer
run: cargo +nightly nextest run
-Z build-std --target=x86_64-unknown-linux-gnu --all-features
env:
RUSTFLAGS: "-Zsanitizer=${{matrix.sanitizer}}"
RUSTDOCFLAGS: "-Zsanitizer=${{matrix.sanitizer}}"
RUSTFLAGS: "-Zsanitizer=${{matrix.sanitizer}} --cfg=asan"
RUSTDOCFLAGS: "-Zsanitizer=${{matrix.sanitizer}} --cfg=asan"

msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Dependency
run: cargo fetch
- uses: actions/cache@v4
id: cache
- uses: Leafwing-Studios/cargo-cache@v2
with:
path: |
target/
key: ${{ runner.os }}-cargo-msrv-${{ hashFiles('**/Cargo.lock') }}
sweep-cache: true
- uses: taiki-e/install-action@cargo-hack
- run: cargo hack check --rust-version --workspace --all-targets --ignore-private --all-features

Expand All @@ -140,14 +120,9 @@ jobs:
submodules: recursive
- name: Install Rust
run: rustup update stable
- name: Dependency
run: cargo fetch
- uses: actions/cache@v4
id: cache
- uses: Leafwing-Studios/cargo-cache@v2
with:
path: |
target/
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
sweep-cache: true
- name: Run Clippy with reviewdog
uses: giraffate/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion jpegxl-rs/src/encode/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl From<ColorEncoding> for JxlColorEncoding {
api::JxlColorEncodingSetToLinearSRGB(color_encoding.as_mut_ptr(), false.into());
}
SrgbLuma => {
api::JxlColorEncodingSetToSRGB(color_encoding.as_mut_ptr(), true.into())
api::JxlColorEncodingSetToSRGB(color_encoding.as_mut_ptr(), true.into());
}
LinearSrgbLuma => {
api::JxlColorEncodingSetToLinearSRGB(color_encoding.as_mut_ptr(), true.into());
Expand Down
5 changes: 4 additions & 1 deletion jpegxl-src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ exclude = [
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)'] }
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(coverage_nightly)',
'cfg(asan)',
] }

[lints.clippy]
pedantic = "warn"
Expand Down
5 changes: 0 additions & 5 deletions jpegxl-src/build.rs

This file was deleted.

65 changes: 50 additions & 15 deletions jpegxl-src/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,18 @@ fn source_dir() -> PathBuf {
}

#[cfg_attr(coverage_nightly, coverage(off))]

/// Builds the JPEG XL library.
///
/// # Panics
///
/// This function will panic if the source directory does not exist or is not a directory.
pub fn build() {
let source = source_dir();
assert!(
source.exists() && source.is_dir(),
"Source directory {source:?} does not exist"
);

let mut config = cmake::Config::new(source);
config
Expand All @@ -52,25 +62,53 @@ pub fn build() {
config.env("CMAKE_BUILD_PARALLEL_LEVEL", format!("{p}"));
}

#[cfg(target_os = "windows")]
{
if cfg!(asan) {
config
.env("SANITIZER", "asan")
.cflag("-g -DADDRESS_SANITIZER -fsanitize=address")
.cxxflag("-g -DADDRESS_SANITIZER -fsanitize=address")
.define("JPEGXL_ENABLE_TCMALLOC", "OFF");
}

if cfg!(windows) {
// For CMake pre-checking
let mut exeflags = "MSVCRTD.lib".to_string();
if cfg!(asan) {
exeflags.push_str(
" clang_rt.asan_dynamic-x86_64.lib clang_rt.asan_dynamic_runtime_thunk-x86_64.lib",
);
}

config
.generator_toolset("ClangCL")
.define(
"CMAKE_VS_GLOBALS",
"UseMultiToolTask=true;EnforceProcessCountAcrossBuilds=true",
) // Enable parallel builds
.define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded")
.define("CMAKE_EXE_LINKER_FLAGS", "MSVCRTD.lib")
.cflag("-Zl");
.define("CMAKE_EXE_LINKER_FLAGS", exeflags)
.cflag("/Zl");
}

let mut prefix = config.build();
prefix.push("lib");
println!("cargo:rustc-link-search=native={}", prefix.display());
prefix.pop();
prefix.push("lib64");
println!("cargo:rustc-link-search=native={}", prefix.display());
let prefix = config.build();

let lib_dir = {
let mut lib_dir = prefix.join("lib");
if lib_dir.exists() {
lib_dir
} else {
lib_dir.pop();
lib_dir.push("lib64");
if lib_dir.exists() {
lib_dir
} else {
panic!(
"Could not find the library directory, please check the files in {prefix:?}"
);
}
}
};
println!("cargo:rustc-link-search=native={}", lib_dir.display());

println!("cargo:rustc-link-lib=static=jxl");
println!("cargo:rustc-link-lib=static=jxl_cms");
Expand All @@ -81,12 +119,9 @@ pub fn build() {
println!("cargo:rustc-link-lib=static=brotlienc");
println!("cargo:rustc-link-lib=static=brotlicommon");

#[cfg(any(target_vendor = "apple", target_os = "freebsd"))]
{
if cfg!(any(target_vendor = "apple", target_os = "freebsd")) {
println!("cargo:rustc-link-lib=c++");
}
#[cfg(target_os = "linux")]
{
} else if cfg!(target_os = "linux") {
println!("cargo:rustc-link-lib=stdc++");
}
}
Expand Down
2 changes: 1 addition & 1 deletion jpegxl-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ pretty_assertions = "1.4.1"

[features]
default = []
vendored = ["jpegxl-src"]
vendored = ["dep:jpegxl-src"]
docs = []
12 changes: 6 additions & 6 deletions jpegxl-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

//! Build script for jpegxl-sys.
use std::env;

fn main() {
#[cfg(all(not(feature = "vendored"), not(feature = "docs")))]
{
use std::env;
if cfg!(all(not(feature = "vendored"), not(feature = "docs"))) {
let version = env!("CARGO_PKG_VERSION")
.split('+')
.nth(1)
Expand All @@ -43,8 +43,8 @@ fn main() {
panic!("Cannot find `libjxl_threads` with version >= {version}")
});
}
} else {
#[cfg(feature = "vendored")]
jpegxl_src::build();
}

#[cfg(feature = "vendored")]
jpegxl_src::build();
}

0 comments on commit 88927fa

Please sign in to comment.