From 800e6a1ae559428688b6be550978e95933c260fb Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Thu, 23 Jun 2022 13:42:49 +0800 Subject: [PATCH 1/6] Fix tests and examples under musl Signed-off-by: Xuanwo --- examples/malloc_hook.rs | 4 ++-- src/collector.rs | 7 ++++++- src/profiler.rs | 11 ++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/examples/malloc_hook.rs b/examples/malloc_hook.rs index 2957c36d..fb19ad2b 100644 --- a/examples/malloc_hook.rs +++ b/examples/malloc_hook.rs @@ -5,13 +5,13 @@ extern crate libc; use pprof; use std::ffi::c_void; -#[cfg(not(target_os = "linux"))] +#[cfg(not(all(target_os = "linux", target_env = "gnu")))] #[allow(clippy::wrong_self_convention)] #[allow(non_upper_case_globals)] static mut __malloc_hook: Option *mut c_void> = None; extern "C" { - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", target_env = "gnu"))] static mut __malloc_hook: Option *mut c_void>; fn malloc(size: usize) -> *mut c_void; diff --git a/src/collector.rs b/src/collector.rs index 0e63b695..d53fef4a 100644 --- a/src/collector.rs +++ b/src/collector.rs @@ -369,8 +369,13 @@ mod malloc_free_test { use std::collections::BTreeMap; use std::ffi::c_void; + #[cfg(not(target_env = "gnu"))] + #[allow(clippy::wrong_self_convention)] + #[allow(non_upper_case_globals)] + static mut __malloc_hook: Option *mut c_void> = None; + extern "C" { - #[cfg(target_os = "linux")] + #[cfg(target_env = "gnu")] static mut __malloc_hook: Option *mut c_void>; fn malloc(size: usize) -> *mut c_void; diff --git a/src/profiler.rs b/src/profiler.rs index 25c7b123..4bc72ad2 100644 --- a/src/profiler.rs +++ b/src/profiler.rs @@ -183,12 +183,12 @@ fn write_thread_name_fallback(current_thread: libc::pthread_t, name: &mut [libc: } } -#[cfg(not(any(target_os = "linux", target_os = "macos")))] +#[cfg(not(all(any(target_os = "linux", target_os = "macos"), target_env = "gnu")))] fn write_thread_name(current_thread: libc::pthread_t, name: &mut [libc::c_char]) { write_thread_name_fallback(current_thread, name); } -#[cfg(any(target_os = "linux", target_os = "macos"))] +#[cfg(all(any(target_os = "linux", target_os = "macos"), target_env = "gnu"))] fn write_thread_name(current_thread: libc::pthread_t, name: &mut [libc::c_char]) { let name_ptr = name as *mut [libc::c_char] as *mut libc::c_char; let ret = unsafe { libc::pthread_getname_np(current_thread, name_ptr, MAX_THREAD_NAME) }; @@ -411,10 +411,15 @@ mod tests { use std::cell::RefCell; use std::ffi::c_void; - use std::ptr::null_mut; + #[cfg(not(target_env = "gnu"))] + #[allow(clippy::wrong_self_convention)] + #[allow(non_upper_case_globals)] + static mut __malloc_hook: Option *mut c_void> = None; + extern "C" { + #[cfg(target_env = "gnu")] static mut __malloc_hook: Option *mut c_void>; fn malloc(size: usize) -> *mut c_void; From 814cdcdba186fb67cf23e1a7869635579e48ee1e Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Thu, 23 Jun 2022 13:47:03 +0800 Subject: [PATCH 2/6] Cover build and test under musl Signed-off-by: Xuanwo --- .github/workflows/rust.yml | 48 +++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b79e23fb..92e272c3 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -43,16 +43,24 @@ jobs: matrix: os: [ubuntu-latest, macos-latest] toolchain: [stable, nightly, 1.56.1] - target: [x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, x86_64-apple-darwin, aarch64-apple-darwin] + target: [ + x86_64-unknown-linux-gnu, + aarch64-unknown-linux-gnu, + x86_64-unknown-linux-musl, + x86_64-apple-darwin, + aarch64-apple-darwin, + ] exclude: - - os: ubuntu-latest - target: x86_64-apple-darwin - - os: ubuntu-latest - target: aarch64-apple-darwin - - os: macos-latest - target: x86_64-unknown-linux-gnu - - os: macos-latest - target: aarch64-unknown-linux-gnu + - os: ubuntu-latest + target: x86_64-apple-darwin + - os: ubuntu-latest + target: aarch64-apple-darwin + - os: macos-latest + target: x86_64-unknown-linux-gnu + - os: macos-latest + target: aarch64-unknown-linux-gnu + - os: macos-latest + target: x86_64-unknown-linux-musl runs-on: ${{ matrix.os }} steps: @@ -92,6 +100,24 @@ jobs: matrix: os: [ubuntu-latest, macos-latest] toolchain: [stable, nightly] + target: [ + x86_64-unknown-linux-gnu, + aarch64-unknown-linux-gnu, + x86_64-unknown-linux-musl, + x86_64-apple-darwin, + aarch64-apple-darwin, + ] + exclude: + - os: ubuntu-latest + target: x86_64-apple-darwin + - os: ubuntu-latest + target: aarch64-apple-darwin + - os: macos-latest + target: x86_64-unknown-linux-gnu + - os: macos-latest + target: aarch64-unknown-linux-gnu + - os: macos-latest + target: x86_64-unknown-linux-musl runs-on: ${{ matrix.os }} steps: @@ -109,10 +135,10 @@ jobs: uses: actions-rs/cargo@v1.0.3 with: command: test - args: --features flamegraph,prost-codec + args: --features flamegraph,prost-codec --target ${{ matrix.target }} - name: Run cargo test protobuf uses: actions-rs/cargo@v1.0.3 with: command: test - args: --features flamegraph,protobuf-codec + args: --features flamegraph,protobuf-codec --target ${{ matrix.target }} From 63844adaf152c6f16e61db2caa629ffcc4dc84d4 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Thu, 23 Jun 2022 14:04:57 +0800 Subject: [PATCH 3/6] Fix target not installed Signed-off-by: Xuanwo --- .github/workflows/rust.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 92e272c3..6cdce07e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -129,6 +129,7 @@ jobs: with: profile: minimal toolchain: ${{ matrix.toolchain }} + target: ${{ matrix.target }} override: true - name: Run cargo test prost From b74c2c29f2a082c8f3a94a16f7a3929e302a258f Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Thu, 23 Jun 2022 14:29:57 +0800 Subject: [PATCH 4/6] Install musl-tools Signed-off-by: Xuanwo --- .github/workflows/rust.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6cdce07e..74ed1103 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -132,6 +132,10 @@ jobs: target: ${{ matrix.target }} override: true + - if: ${{ matrix.target == 'x86_64-unknown-linux-musl' }} + name: Install musl + run: sudo apt install musl-tools + - name: Run cargo test prost uses: actions-rs/cargo@v1.0.3 with: From 708034e592860d85ffc8e7c9380aec47088fc2db Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Thu, 23 Jun 2022 14:31:11 +0800 Subject: [PATCH 5/6] Don't run test for aarch Signed-off-by: Xuanwo --- .github/workflows/rust.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 74ed1103..a92b7531 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -102,20 +102,14 @@ jobs: toolchain: [stable, nightly] target: [ x86_64-unknown-linux-gnu, - aarch64-unknown-linux-gnu, x86_64-unknown-linux-musl, x86_64-apple-darwin, - aarch64-apple-darwin, ] exclude: - os: ubuntu-latest target: x86_64-apple-darwin - - os: ubuntu-latest - target: aarch64-apple-darwin - os: macos-latest target: x86_64-unknown-linux-gnu - - os: macos-latest - target: aarch64-unknown-linux-gnu - os: macos-latest target: x86_64-unknown-linux-musl runs-on: ${{ matrix.os }} From 245a1460a19b8f17d2026b43bb1aa326982cd737 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Thu, 23 Jun 2022 14:31:49 +0800 Subject: [PATCH 6/6] Cancel previous jobs Signed-off-by: Xuanwo --- .github/workflows/rust.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a92b7531..10a9a0eb 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -2,6 +2,10 @@ on: [push, pull_request] name: build +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} + cancel-in-progress: true + jobs: lint: name: Format and Clippy