diff --git a/profiling/build.rs b/profiling/build.rs index 37db945a45..96e7f5bc26 100644 --- a/profiling/build.rs +++ b/profiling/build.rs @@ -1,6 +1,6 @@ use bindgen::callbacks::IntKind; use std::collections::HashSet; -use std::env; +use std::{env, fs}; use std::path::Path; use std::path::PathBuf; use std::process::Command; @@ -21,6 +21,14 @@ fn main() { } } + // Read the version from the VERSION file + let version = fs::read_to_string("../VERSION") + .expect("Failed to read VERSION file") + .trim() + .to_string(); + println!("cargo:rustc-env=PROFILER_VERSION={}", version); + println!("cargo:rerun-if-changed=../VERSION"); + let php_config_includes = std::str::from_utf8(php_config_includes_output.stdout.as_slice()) .expect("`php-config`'s stdout to be valid utf8"); diff --git a/profiling/src/lib.rs b/profiling/src/lib.rs index 0d6f8670c6..f73565fba0 100644 --- a/profiling/src/lib.rs +++ b/profiling/src/lib.rs @@ -58,7 +58,7 @@ static PROFILER_NAME_CSTR: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked( /// Version of the profiling module and zend_extension. Must not contain any /// interior null bytes and must be null terminated. -static PROFILER_VERSION: &[u8] = concat!(include_str!("../../VERSION"), "\0").as_bytes(); +static PROFILER_VERSION: &[u8] = concat!(env!("PROFILER_VERSION"), "\0").as_bytes(); /// Version ID of PHP at run-time, not the version it was built against at /// compile-time. Its value is overwritten during minit. @@ -82,7 +82,7 @@ lazy_static! { static ref LAZY_STATICS_TAGS: Vec = { vec![ tag!("language", "php"), - tag!("profiler_version", include_str!("../../VERSION")), + tag!("profiler_version", env!("PROFILER_VERSION")), // Safety: calling getpid() is safe. Tag::new("process_id", unsafe { libc::getpid() }.to_string()) .expect("process_id tag to be valid"),