Skip to content

Commit

Permalink
feat: Fix and cover tests for target x86_64-unknown-linux-musl (#140)
Browse files Browse the repository at this point in the history
* Fix tests and examples under musl

Signed-off-by: Xuanwo <github@xuanwo.io>

* Cover build and test under musl

Signed-off-by: Xuanwo <github@xuanwo.io>

* Fix target not installed

Signed-off-by: Xuanwo <github@xuanwo.io>

* Install musl-tools

Signed-off-by: Xuanwo <github@xuanwo.io>

* Don't run test for aarch

Signed-off-by: Xuanwo <github@xuanwo.io>

* Cancel previous jobs

Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo committed Jun 24, 2022
1 parent a2dbfa2 commit 1b19478
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 17 deletions.
51 changes: 40 additions & 11 deletions .github/workflows/rust.yml
Expand Up @@ -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
Expand Down Expand Up @@ -43,16 +47,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:
Expand Down Expand Up @@ -92,6 +104,18 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest]
toolchain: [stable, nightly]
target: [
x86_64-unknown-linux-gnu,
x86_64-unknown-linux-musl,
x86_64-apple-darwin,
]
exclude:
- os: ubuntu-latest
target: x86_64-apple-darwin
- os: macos-latest
target: x86_64-unknown-linux-gnu
- os: macos-latest
target: x86_64-unknown-linux-musl
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -103,16 +127,21 @@ jobs:
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
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:
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 }}
4 changes: 2 additions & 2 deletions examples/malloc_hook.rs
Expand Up @@ -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<extern "C" fn(size: usize) -> *mut c_void> = None;

extern "C" {
#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", target_env = "gnu"))]
static mut __malloc_hook: Option<extern "C" fn(size: usize) -> *mut c_void>;

fn malloc(size: usize) -> *mut c_void;
Expand Down
7 changes: 6 additions & 1 deletion src/collector.rs
Expand Up @@ -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<extern "C" fn(size: usize) -> *mut c_void> = None;

extern "C" {
#[cfg(target_os = "linux")]
#[cfg(target_env = "gnu")]
static mut __malloc_hook: Option<extern "C" fn(size: usize) -> *mut c_void>;

fn malloc(size: usize) -> *mut c_void;
Expand Down
11 changes: 8 additions & 3 deletions src/profiler.rs
Expand Up @@ -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) };
Expand Down Expand Up @@ -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<extern "C" fn(size: usize) -> *mut c_void> = None;

extern "C" {
#[cfg(target_env = "gnu")]
static mut __malloc_hook: Option<extern "C" fn(size: usize) -> *mut c_void>;

fn malloc(size: usize) -> *mut c_void;
Expand Down

0 comments on commit 1b19478

Please sign in to comment.