Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions builder/src/arch/apple.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use std::ffi::OsStr;
use std::process::Command;

Expand Down Expand Up @@ -32,3 +33,7 @@ pub fn strip_libraries(lib_path: &str) {
}

pub fn add_additional_files(_lib_path: &str, _target_path: &OsStr) {}

pub fn add_pkg_config(crate_path: &str, target_path: &str, version: &str) -> Result<()> {
super::generate_pkg_config(crate_path, target_path, version, NATIVE_LIBS)
}
5 changes: 5 additions & 0 deletions builder/src/arch/linux.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use std::ffi::OsStr;
use std::process::Command;

Expand Down Expand Up @@ -56,3 +57,7 @@ pub fn strip_libraries(lib_path: &str) {
}

pub fn add_additional_files(_lib_path: &str, _target_path: &OsStr) {}

pub fn add_pkg_config(crate_path: &str, target_path: &str, version: &str) -> Result<()> {
super::generate_pkg_config(crate_path, target_path, version, NATIVE_LIBS)
}
50 changes: 50 additions & 0 deletions builder/src/arch/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use std::ffi::OsStr;
use std::fs;
use std::path::{Path, PathBuf};

use crate::utils::{file_replace, project_root};

pub fn generate_pkg_config(
crate_path: &str,
target_path: &str,
version: &str,
native_libs: &str,
) -> Result<()> {
let files: [&str; 3] = [
"datadog_profiling.pc",
"datadog_profiling_with_rpath.pc",
"datadog_profiling-static.pc",
];

let pc_dir = Path::new(target_path);
fs::create_dir_all(pc_dir).expect("Failed to create pkgconfig directory");

for file in files.iter() {
let file_in = file.to_string() + ".in";

let mut pc_origin: PathBuf = project_root();
pc_origin.push(crate_path);
pc_origin.push(file_in);

let pc_target: PathBuf = [pc_dir.as_os_str(), OsStr::new(file)].iter().collect();

file_replace(
pc_origin.to_str().unwrap(),
pc_target.to_str().unwrap(),
"@Datadog_VERSION@",
version,
)?;

if *file == files[2] {
file_replace(
pc_origin.to_str().unwrap(),
pc_target.to_str().unwrap(),
"@Datadog_LIBRARIES@",
native_libs,
)?;
}
}
Ok(())
}

#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
#[cfg(all(target_os = "linux", target_env = "gnu"))]
mod linux;
Expand Down
5 changes: 5 additions & 0 deletions builder/src/arch/musl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use std::ffi::OsStr;
use std::process::Command;

Expand Down Expand Up @@ -56,3 +57,7 @@ pub fn strip_libraries(lib_path: &str) {
}

pub fn add_additional_files(_lib_path: &str, _target_path: &OsStr) {}

pub fn add_pkg_config(crate_path: &str, target_path: &str, version: &str) -> Result<()> {
super::generate_pkg_config(crate_path, target_path, version, NATIVE_LIBS)
}
19 changes: 15 additions & 4 deletions builder/src/arch/windows.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use std::ffi::OsStr;
use std::fs;
use std::path::PathBuf;

pub const NATIVE_LIBS: &str = "";
pub const PROF_DYNAMIC_LIB: &str = "datadog_profiling.dll";
pub const PROF_STATIC_LIB: &str = "datadog_profiling.lib";
pub const PROF_PDB: &str = "datadog_profiling.pdb";
pub const PROF_DYNAMIC_LIB: &str = "datadog_profiling_ffi.dll";
pub const PROF_STATIC_LIB: &str = "datadog_profiling_ffi.lib";
pub const PROF_PDB: &str = "datadog_profiling_ffi.pdb";
pub const PROF_DYNAMIC_LIB_FFI: &str = "datadog_profiling_ffi.dll";
pub const PROF_STATIC_LIB_FFI: &str = "datadog_profiling_ffi.lib";
pub const PROF_PDB_FFI: &str = "datadog_profiling_ffi.pdb";
pub const PROF_DLL_IMPORT_LIB_FFI: &str = "datadog_profiling_ffi.dll.lib";
pub const BUILD_CRASHTRACKER: bool = false;
pub const RUSTFLAGS: [&str; 4] = [
"-C",
Expand All @@ -25,6 +27,15 @@ pub fn strip_libraries(_lib_path: &str) {}
pub fn add_additional_files(lib_path: &str, target_path: &OsStr) {
let from_pdb: PathBuf = [lib_path, PROF_PDB_FFI].iter().collect();
let to_pdb: PathBuf = [target_path, OsStr::new(PROF_PDB)].iter().collect();

fs::copy(from_pdb, to_pdb).expect("unable to copy pdb file");

let from_imp: PathBuf = [lib_path, PROF_DLL_IMPORT_LIB_FFI].iter().collect();
let to_imp: PathBuf = [target_path, OsStr::new(PROF_DLL_IMPORT_LIB_FFI)]
.iter()
.collect();
fs::copy(from_imp, to_imp).expect("unable to copy dll import lib");
}

pub fn add_pkg_config(_crate_path: &str, _target_path: &str, _version: &str) -> Result<()> {
Ok(())
}
13 changes: 8 additions & 5 deletions builder/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,14 @@ impl Builder {
fs::create_dir_all(Path::new(self.target_include.as_ref()))
.expect("Failed to create include directory");
fs::create_dir_all(Path::new(self.target_lib.as_ref()))
.expect("Failed to create include directory");
fs::create_dir_all(Path::new(self.target_bin.as_ref()))
.expect("Failed to create include directory");
fs::create_dir_all(Path::new(self.target_pkconfig.as_ref()))
.expect("Failed to create include directory");
.expect("Failed to create lib directory");
#[cfg(not(target_os = "windows"))]
{
fs::create_dir_all(Path::new(self.target_bin.as_ref()))
.expect("Failed to create bin directory");
fs::create_dir_all(Path::new(self.target_pkconfig.as_ref()))
.expect("Failed to create pkgconfig directory");
}
}

pub fn add_cmake(&self) {
Expand Down
44 changes: 6 additions & 38 deletions builder/src/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::arch;
use crate::module::Module;
use crate::utils::{adjust_extern_symbols, file_replace, project_root, wait_for_success};
use crate::utils::{adjust_extern_symbols, project_root, wait_for_success};
use anyhow::Result;
use serde::Deserialize;
use std::ffi::OsStr;
Expand Down Expand Up @@ -118,43 +118,11 @@ impl Profiling {
}

fn add_pkg_config(&self) -> Result<()> {
let files: [&str; 3] = [
"datadog_profiling.pc",
"datadog_profiling_with_rpath.pc",
"datadog_profiling-static.pc",
];

//Create directory
let pc_dir = Path::new(self.target_pkconfig.as_ref());
fs::create_dir_all(pc_dir).expect("Failed to create pkgconfig directory");

// Create files
for file in files.iter() {
let file_in = file.to_string() + ".in";

let mut pc_origin: PathBuf = project_root();
pc_origin.push(CRATE_FOLDER);
pc_origin.push(file_in);

let pc_target: PathBuf = [pc_dir.as_os_str(), OsStr::new(file)].iter().collect();

file_replace(
pc_origin.to_str().unwrap(),
pc_target.to_str().unwrap(),
"@Datadog_VERSION@",
&self.version,
)?;

if *file == files[2] {
file_replace(
pc_origin.to_str().unwrap(),
pc_target.to_str().unwrap(),
"@Datadog_LIBRARIES@",
arch::NATIVE_LIBS,
)?;
}
}
Ok(())
arch::add_pkg_config(
CRATE_FOLDER,
self.target_pkconfig.as_ref(),
self.version.as_ref(),
)
}
}

Expand Down
28 changes: 27 additions & 1 deletion tools/src/bin/ffi_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,31 @@ fn library_search_path_env(lib_dir: &Path) -> (String, String) {
(search_path_var.to_string(), lib_path)
}

/// Env vars applied to every spawned test, regardless of name.
///
/// On Windows the test executables are dynamically linked against
/// `datadog_profiling_ffi.dll` (CMake's `find_library` picks the import library
/// over the static `.lib`). The DLL lives in `release/lib/` but the executables
/// run from a temp work directory, so without help Windows can't locate it and
/// every test exits with STATUS_DLL_NOT_FOUND (0xC0000135).
#[cfg(windows)]
fn base_env_vars(project_root: &Path) -> Vec<(String, String)> {
let lib_dir = project_root.join("release").join("lib");
if !lib_dir.exists() {
return vec![];
}
let new_path = match std::env::var("PATH") {
Ok(existing) if !existing.is_empty() => format!("{};{}", lib_dir.display(), existing),
_ => lib_dir.display().to_string(),
};
vec![("PATH".to_string(), new_path)]
}

#[cfg(not(windows))]
fn base_env_vars(_project_root: &Path) -> Vec<(String, String)> {
vec![]
}

/// Per-test environment variables. The runner sets these before spawning
/// the test executable so that tests which need external resources (e.g. the
/// receiver binary) can find them without hard-coding paths.
Expand Down Expand Up @@ -528,7 +553,8 @@ fn run_test(
) -> TestResult {
let is_expected_failure = expected_failures().contains_key(name);
let expected_crash = expected_crashes().get(name);
let env_vars = per_test_env(name, project_root, work_dir);
let mut env_vars = base_env_vars(project_root);
env_vars.extend(per_test_env(name, project_root, work_dir));
let start = Instant::now();

let child = match spawn_test(exe_path, work_dir, &env_vars) {
Expand Down
89 changes: 0 additions & 89 deletions windows/build-artifacts.ps1

This file was deleted.

Loading
Loading