diff --git a/Cargo.lock b/Cargo.lock index f956cd04b4..a1d84d0a16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -655,6 +655,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "current_platform" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a74858bcfe44b22016cb49337d7b6f04618c58e5dbfdef61b06b8c434324a0bc" + [[package]] name = "darling" version = "0.20.8" @@ -2307,6 +2313,7 @@ name = "php_sidecar_mockgen" version = "0.1.0" dependencies = [ "cc_utils", + "current_platform", "sidecar_mockgen", ] diff --git a/Makefile b/Makefile index 70cea4bd77..b948f670c6 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,13 @@ INIT_HOOK_TEST_FILES = $(shell find tests/C2PHP -name '*.phpt' -o -name '*.inc' M4_FILES = $(shell find m4 -name '*.m4*' | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' ) $(BUILD_DIR)/config.m4 XDEBUG_SO_FILE = $(shell find $(shell php-config --extension-dir) -type f -name "xdebug*.so" -exec basename {} \; | tail -n 1) +# Make 'sed -i' portable +ifeq ($(shell uname),Darwin) + SED_I = sed -i '' +else + SED_I = sed -i +endif + all: $(BUILD_DIR)/configure $(SO_FILE) # The following differentiation exists so we can build only (but always) the relevant files while executing tests @@ -67,13 +74,13 @@ $(BUILD_DIR)/%Cargo.toml: %Cargo.toml $(Q) echo Copying $*Cargo.toml to $@ $(Q) mkdir -p $(dir $@) $(Q) cp -a $*Cargo.toml $@ - sed -i -E 's/"\.\.\/([^"]*)"/"..\/..\/..\/\1"/' $@ + $(SED_I) -E 's/"\.\.\/([^"]*)"/"..\/..\/..\/\1"/' $@ $(BUILD_DIR)/Cargo.toml: Cargo.toml $(Q) echo Copying Cargo.toml to $@ $(Q) mkdir -p $(dir $@) $(Q) cp -a Cargo.toml $@ - sed -i -E 's/, "profiling",?//' $@ + $(SED_I) -E 's/, "profiling",?//' $@ $(BUILD_DIR)/%: % $(Q) echo Copying $* to $@ @@ -86,7 +93,7 @@ JUNIT_RESULTS_DIR := $(shell pwd) all: $(BUILD_DIR)/configure $(SO_FILE) $(BUILD_DIR)/configure: $(M4_FILES) $(BUILD_DIR)/ddtrace.sym $(BUILD_DIR)/VERSION - $(Q) (cd $(BUILD_DIR); phpize && sed -i 's/\/FAILED/\/\\bFAILED/' $(BUILD_DIR)/run-tests.php) # Fix PHP 5.4 exit code bug when running selected tests (FAILED vs XFAILED) + $(Q) (cd $(BUILD_DIR); phpize && $(SED_I) 's/\/FAILED/\/\\bFAILED/' $(BUILD_DIR)/run-tests.php) # Fix PHP 5.4 exit code bug when running selected tests (FAILED vs XFAILED) $(BUILD_DIR)/Makefile: $(BUILD_DIR)/configure $(Q) (cd $(BUILD_DIR); ./configure --$(if $(RUST_DEBUG_BUILD),enable,disable)-ddtrace-rust-debug) @@ -289,7 +296,7 @@ test_coverage_collect: --exclude "$(BUILD_DIR)/src/dogstatsd/*" \ --exclude "$(BUILD_DIR)/src/dogstatsd/dogstatsd_client/*" \ --output-file $(PROJECT_ROOT)/tmp/coverage.info - $(Q) sed -i 's+tmp/build_extension/ext+ext+g' $(PROJECT_ROOT)/tmp/coverage.info + $(Q) $(SED_I) 's+tmp/build_extension/ext+ext+g' $(PROJECT_ROOT)/tmp/coverage.info test_coverage_output: $(Q) genhtml \ diff --git a/components-rs/php_sidecar_mockgen/Cargo.toml b/components-rs/php_sidecar_mockgen/Cargo.toml index 21a3a18987..4b010850c2 100644 --- a/components-rs/php_sidecar_mockgen/Cargo.toml +++ b/components-rs/php_sidecar_mockgen/Cargo.toml @@ -5,6 +5,7 @@ version = "0.1.0" [dependencies] cc_utils = { path = "../../libdatadog/tools/cc_utils" } +current_platform = "0.2.0" sidecar_mockgen = { path = "../../libdatadog/tools/sidecar_mockgen" } [[bin]] diff --git a/components-rs/php_sidecar_mockgen/src/bin/php_sidecar_mockgen.rs b/components-rs/php_sidecar_mockgen/src/bin/php_sidecar_mockgen.rs index d7471a0875..a31c034e07 100644 --- a/components-rs/php_sidecar_mockgen/src/bin/php_sidecar_mockgen.rs +++ b/components-rs/php_sidecar_mockgen/src/bin/php_sidecar_mockgen.rs @@ -44,7 +44,22 @@ fn main() { if fs::metadata("mock_php.shared_lib").map_or(true, |m| m.modified().unwrap() < source_modified) { env::set_var("OPT_LEVEL", "2"); + let mut cc_build = cc::Build::new(); + + // The 'host' and 'target' options are required to compile. + // They can be provided using the HOST and TARGET environment variables. + // On Linux, these environment variables can be empty strings, but it's not the case on macOS. + let host = std::env::var("HOST").unwrap_or("".to_string()); + if host == "" { + cc_build.host(current_platform::CURRENT_PLATFORM); + } + let target = std::env::var("TARGET").unwrap_or("".to_string()); + if target == "" { + cc_build.target(current_platform::CURRENT_PLATFORM); + } + cc_utils::ImprovedBuild::new() + .set_cc_builder(cc_build) .file("mock_php_syms.c") .link_dynamically("dl") .warnings(true)