Skip to content

Commit 2be9b71

Browse files
guard VERSION against CRLF (#3049)
1 parent 8413b26 commit 2be9b71

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

profiling/build.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bindgen::callbacks::IntKind;
22
use std::collections::HashSet;
3-
use std::env;
3+
use std::{env, fs};
44
use std::path::Path;
55
use std::path::PathBuf;
66
use std::process::Command;
@@ -21,6 +21,14 @@ fn main() {
2121
}
2222
}
2323

24+
// Read the version from the VERSION file
25+
let version = fs::read_to_string("../VERSION")
26+
.expect("Failed to read VERSION file")
27+
.trim()
28+
.to_string();
29+
println!("cargo:rustc-env=PROFILER_VERSION={}", version);
30+
println!("cargo:rerun-if-changed=../VERSION");
31+
2432
let php_config_includes = std::str::from_utf8(php_config_includes_output.stdout.as_slice())
2533
.expect("`php-config`'s stdout to be valid utf8");
2634

profiling/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static PROFILER_NAME_CSTR: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(
5858

5959
/// Version of the profiling module and zend_extension. Must not contain any
6060
/// interior null bytes and must be null terminated.
61-
static PROFILER_VERSION: &[u8] = concat!(include_str!("../../VERSION"), "\0").as_bytes();
61+
static PROFILER_VERSION: &[u8] = concat!(env!("PROFILER_VERSION"), "\0").as_bytes();
6262

6363
/// Version ID of PHP at run-time, not the version it was built against at
6464
/// compile-time. Its value is overwritten during minit.
@@ -82,7 +82,7 @@ lazy_static! {
8282
static ref LAZY_STATICS_TAGS: Vec<Tag> = {
8383
vec![
8484
tag!("language", "php"),
85-
tag!("profiler_version", include_str!("../../VERSION")),
85+
tag!("profiler_version", env!("PROFILER_VERSION")),
8686
// Safety: calling getpid() is safe.
8787
Tag::new("process_id", unsafe { libc::getpid() }.to_string())
8888
.expect("process_id tag to be valid"),

0 commit comments

Comments
 (0)