-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No longer compile the mockgen as part of the rust build
Instead we run a separate rust executable to produce it, and it will be included as a normal .c file in the ddtrace C build This will allow us to compile the sidecar once for all versions as well as have the debug symbols for the sidecar just once Signed-off-by: Bob Weinand <[email protected]>
- Loading branch information
Showing
9 changed files
with
124 additions
and
78 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
edition = "2021" | ||
name = "php_sidecar_mockgen" | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
cc_utils = { path = "../../libdatadog/tools/cc_utils" } | ||
sidecar_mockgen = { path = "../../libdatadog/tools/sidecar_mockgen" } | ||
|
||
[[bin]] | ||
name = "php_sidecar_mockgen" |
75 changes: 75 additions & 0 deletions
75
components-rs/php_sidecar_mockgen/src/bin/php_sidecar_mockgen.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc. | ||
|
||
pub use cc_utils::cc; | ||
pub use sidecar_mockgen::generate_mock_symbols; | ||
use std::path::Path; | ||
use std::{env, fs, process}; | ||
|
||
fn main() { | ||
// This script is necessary to avoid the linker puking when the sidecar tries to load our ddtrace.so | ||
// As php itself is not available within the sidecar, it needs to make sure that all symbols ddtrace.so depends on, are available. | ||
// The mock_generator takes care of generating these symbols. | ||
let args: Vec<_> = env::args_os().collect(); | ||
if args.len() < 3 { | ||
eprintln!( | ||
"Needs at least 3 args: the output file, the shared object file followed by at least one object file" | ||
); | ||
process::exit(1); | ||
} | ||
|
||
let output_path = Path::new(&args[1]); | ||
let binary_path = Path::new(&args[2]); | ||
let object_paths: Vec<_> = args.iter().skip(3).map(Path::new).collect(); | ||
let mock_symbols = match generate_mock_symbols(binary_path, object_paths.as_slice()) { | ||
Ok(symbols) => symbols, | ||
Err(err) => { | ||
eprintln!("Failed generating mock_php_syms.c: {}", err); | ||
process::exit(1); | ||
} | ||
}; | ||
|
||
if fs::read("mock_php_syms.c") | ||
.ok() | ||
.map(|contents| contents == mock_symbols.as_str().as_bytes()) | ||
!= Some(true) | ||
{ | ||
if let Err(err) = fs::write("mock_php_syms.c", mock_symbols) { | ||
eprintln!("Failed generating mock_php_syms.c: {}", err); | ||
process::exit(1); | ||
} | ||
} | ||
|
||
let source_modified = fs::metadata("mock_php_syms.c").unwrap().modified().unwrap(); | ||
if fs::metadata("mock_php.shared_lib").map_or(true, |m| m.modified().unwrap() < source_modified) { | ||
env::set_var("OPT_LEVEL", "2"); | ||
|
||
cc_utils::ImprovedBuild::new() | ||
.file("mock_php_syms.c") | ||
.link_dynamically("dl") | ||
.warnings(true) | ||
.warnings_into_errors(true) | ||
.emit_rerun_if_env_changed(false) | ||
.try_compile_shared_lib("mock_php.shared_lib") | ||
.unwrap(); | ||
|
||
let bin = match fs::read("mock_php.shared_lib") { | ||
Ok(bin) => bin, | ||
Err(err) => { | ||
eprintln!("Failed opening generated mock_php.shared_lib: {}", err); | ||
process::exit(1); | ||
} | ||
}; | ||
|
||
let comma_separated = bin.iter().map(|byte| format!("{byte:#X}")).collect::<Vec<String>>().join(","); | ||
let out = format!(r#" | ||
const unsigned char DDTRACE_MOCK_PHP[] = {{{comma_separated}}}; | ||
const void *DDTRACE_MOCK_PHP_SIZE = (void *) sizeof(DDTRACE_MOCK_PHP); | ||
"#); | ||
|
||
if let Err(err) = fs::write(output_path, out) { | ||
eprintln!("Failed generating {:?}: {}", output_path, err); | ||
process::exit(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters