33//! This script compiles the `libcodspeed_preload.so` shared library that is used
44//! to inject instrumentation into child processes via LD_PRELOAD.
55//!
6- //! The library is built using the `core.c` and headers from the `codspeed` crate's
7- //! `instrument-hooks` directory.
8- //!
9- //! # Environment Variables
10- //!
11- //! - `CODSPEED_INSTRUMENT_HOOKS_DIR`: Optional override for the instrument-hooks
12- //! source directory. If not set, the build script will locate it from the
13- //! `codspeed` crate in the cargo registry.
6+ //! The library is built using the `core.c` and headers from the `instrument-hooks-bindings`
7+ //! crate's `instrument-hooks` directory.
148
15- use cargo_metadata:: MetadataCommand ;
169use std:: env;
1710use std:: path:: PathBuf ;
1811
@@ -25,7 +18,6 @@ struct PreloadConstants {
2518 /// Integration name reported to CodSpeed.
2619 integration_name : & ' static str ,
2720 /// Integration version reported to CodSpeed.
28- /// This should match the version of the `codspeed` crate dependency.
2921 integration_version : & ' static str ,
3022 /// Filename for the preload shared library.
3123 preload_lib_filename : & ' static str ,
@@ -58,11 +50,11 @@ fn main() {
5850 let manifest_dir = PathBuf :: from ( env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ) ;
5951
6052 // Try to get the instrument-hooks directory from the environment variable first,
61- // otherwise locate it from the codspeed crate
62- let instrument_hooks_dir = match env :: var ( "CODSPEED_INSTRUMENT_HOOKS_DIR" ) {
63- Ok ( dir ) => PathBuf :: from ( dir ) ,
64- Err ( _ ) => find_codspeed_instrument_hooks_dir ( ) ,
65- } ;
53+ // otherwise use the one from the instrument-hooks-bindings crate
54+ let instrument_hooks_dir = manifest_dir
55+ . parent ( )
56+ . unwrap ( )
57+ . join ( "instrument-hooks-bindings/instrument-hooks" ) ;
6658
6759 // Build the preload shared library
6860 let paths = PreloadBuildPaths {
@@ -130,40 +122,12 @@ fn build_shared_library(paths: &PreloadBuildPaths, constants: &PreloadConstants)
130122 }
131123}
132124
133- /// Find the instrument-hooks directory from the codspeed crate using cargo_metadata
134- fn find_codspeed_instrument_hooks_dir ( ) -> PathBuf {
135- let metadata = MetadataCommand :: new ( )
136- . exec ( )
137- . expect ( "Failed to run cargo metadata" ) ;
138-
139- // Find the codspeed package in the resolved dependencies
140- let codspeed_pkg = metadata
141- . packages
142- . iter ( )
143- . find ( |p| p. name == "codspeed" )
144- . expect ( "codspeed crate not found in dependencies" ) ;
145-
146- let codspeed_dir = codspeed_pkg
147- . manifest_path
148- . parent ( )
149- . expect ( "Failed to get codspeed crate directory" ) ;
150-
151- let instrument_hooks_dir = codspeed_dir. join ( "instrument-hooks" ) ;
152-
153- if !instrument_hooks_dir. exists ( ) {
154- panic ! ( "instrument-hooks directory not found at {instrument_hooks_dir}" ) ;
155- }
156-
157- instrument_hooks_dir. into_std_path_buf ( )
158- }
159-
160125impl Default for PreloadConstants {
161- // TODO(COD-1736): Stop impersonating codspeed-rust 🥸
162126 fn default ( ) -> Self {
163127 Self {
164128 uri_env : "CODSPEED_BENCH_URI" ,
165- integration_name : "codspeed-rust " ,
166- integration_version : "4.2.0" ,
129+ integration_name : "exec-harness " ,
130+ integration_version : env ! ( "CARGO_PKG_VERSION" ) ,
167131 preload_lib_filename : "libcodspeed_preload.so" ,
168132 }
169133 }
@@ -185,13 +149,13 @@ impl PreloadBuildPaths {
185149 fn check_sources_exist ( & self ) {
186150 if !self . core_c . exists ( ) {
187151 panic ! (
188- "core.c not found at {}. Make sure the codspeed crate is available." ,
152+ "core.c not found at {}. Make sure the instrument-hooks-bindings crate is available." ,
189153 self . core_c. display( )
190154 ) ;
191155 }
192156 if !self . includes_dir . exists ( ) {
193157 panic ! (
194- "includes directory not found at {}. Make sure the codspeed crate is available." ,
158+ "includes directory not found at {}. Make sure the instrument-hooks-bindings crate is available." ,
195159 self . includes_dir. display( )
196160 ) ;
197161 }
0 commit comments