File tree Expand file tree Collapse file tree 2 files changed +17
-16
lines changed Expand file tree Collapse file tree 2 files changed +17
-16
lines changed Original file line number Diff line number Diff line change 11fn main ( ) {
2+ println ! ( "cargo:rustc-check-cfg=cfg(use_instrument_hooks)" ) ;
3+
24 println ! ( "cargo:rerun-if-changed=instrument-hooks/dist/core.c" ) ;
35 println ! ( "cargo:rerun-if-changed=instrument-hooks/includes/core.h" ) ;
46 println ! ( "cargo:rerun-if-changed=build.rs" ) ;
57
6- if cfg ! ( not( target_os = "linux" ) ) {
7- // The instrument-hooks library is only supported on Linux.
8- return ;
9- }
10-
118 let mut build = cc:: Build :: new ( ) ;
129 build
1310 . flag ( "-std=c11" )
@@ -18,13 +15,17 @@ fn main() {
1815 . cargo_warnings ( false ) ;
1916
2017 let result = build. try_compile ( "instrument_hooks" ) ;
21- if let Err ( e) = result {
22- let compiler = build. try_get_compiler ( ) . expect ( "Failed to get C compiler" ) ;
18+ match result {
19+ Ok ( _) => println ! ( "cargo:rustc-cfg=use_instrument_hooks" ) ,
20+ Err ( e) => {
21+ let compiler = build. try_get_compiler ( ) . expect ( "Failed to get C compiler" ) ;
2322
24- eprintln ! ( "\n \n ERROR: Failed to compile instrument-hooks native library with cc-rs. Ensure you have an up-to-date C compiler installed." ) ;
25- eprintln ! ( "Compiler information: {compiler:?}" ) ;
26- eprintln ! ( "Compilation error: {e}" ) ;
23+ eprintln ! ( "\n \n WARNING: Failed to compile instrument-hooks native library with cc-rs." ) ;
24+ eprintln ! ( "The library will still compile, but instrument-hooks functionality will be disabled." ) ;
25+ eprintln ! ( "Compiler information: {compiler:?}" ) ;
26+ eprintln ! ( "Compilation error: {e}\n " ) ;
2727
28- std:: process:: exit ( 1 ) ;
28+ println ! ( "cargo:warning=Failed to compile instrument-hooks native library with cc-rs. Continuing with noop implementation." ) ;
29+ }
2930 }
3031}
Original file line number Diff line number Diff line change 1- #[ cfg( target_os = "linux" ) ]
1+ #[ cfg( use_instrument_hooks ) ]
22mod ffi;
33
4- #[ cfg( target_os = "linux" ) ]
4+ #[ cfg( use_instrument_hooks ) ]
55mod linux_impl {
66 use nix:: sys:: time:: TimeValLike ;
77
@@ -131,7 +131,7 @@ mod linux_impl {
131131 }
132132}
133133
134- #[ cfg( not( target_os = "linux" ) ) ]
134+ #[ cfg( not( use_instrument_hooks ) ) ]
135135mod other_impl {
136136 pub struct InstrumentHooks ;
137137
@@ -169,10 +169,10 @@ mod other_impl {
169169 }
170170}
171171
172- #[ cfg( target_os = "linux" ) ]
172+ #[ cfg( use_instrument_hooks ) ]
173173pub use linux_impl:: InstrumentHooks ;
174174
175- #[ cfg( not( target_os = "linux" ) ) ]
175+ #[ cfg( not( use_instrument_hooks ) ) ]
176176pub use other_impl:: InstrumentHooks ;
177177
178178#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments