Skip to content

Commit 9c30399

Browse files
committed
refactor: move add_pkg_config to arch
1 parent 293cc45 commit 9c30399

6 files changed

Lines changed: 79 additions & 42 deletions

File tree

builder/src/arch/apple.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use anyhow::Result;
45
use std::ffi::OsStr;
56
use std::process::Command;
67

@@ -32,3 +33,7 @@ pub fn strip_libraries(lib_path: &str) {
3233
}
3334

3435
pub fn add_additional_files(_lib_path: &str, _target_path: &OsStr) {}
36+
37+
pub fn add_pkg_config(crate_path: &str, target_path: &str, version: &str) -> Result<()> {
38+
super::generate_pkg_config(crate_path, target_path, version, NATIVE_LIBS)
39+
}

builder/src/arch/linux.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use anyhow::Result;
45
use std::ffi::OsStr;
56
use std::process::Command;
67

@@ -56,3 +57,7 @@ pub fn strip_libraries(lib_path: &str) {
5657
}
5758

5859
pub fn add_additional_files(_lib_path: &str, _target_path: &OsStr) {}
60+
61+
pub fn add_pkg_config(crate_path: &str, target_path: &str, version: &str) -> Result<()> {
62+
super::generate_pkg_config(crate_path, target_path, version, NATIVE_LIBS)
63+
}

builder/src/arch/mod.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,56 @@
11
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use anyhow::Result;
5+
use std::ffi::OsStr;
6+
use std::fs;
7+
use std::path::{Path, PathBuf};
8+
9+
use crate::utils::{file_replace, project_root};
10+
11+
pub fn generate_pkg_config(
12+
crate_path: &str,
13+
target_path: &str,
14+
version: &str,
15+
native_libs: &str,
16+
) -> Result<()> {
17+
let files: [&str; 3] = [
18+
"datadog_profiling.pc",
19+
"datadog_profiling_with_rpath.pc",
20+
"datadog_profiling-static.pc",
21+
];
22+
23+
let pc_dir = Path::new(target_path);
24+
fs::create_dir_all(pc_dir).expect("Failed to create pkgconfig directory");
25+
26+
for file in files.iter() {
27+
let file_in = file.to_string() + ".in";
28+
29+
let mut pc_origin: PathBuf = project_root();
30+
pc_origin.push(crate_path);
31+
pc_origin.push(file_in);
32+
33+
let pc_target: PathBuf = [pc_dir.as_os_str(), OsStr::new(file)].iter().collect();
34+
35+
file_replace(
36+
pc_origin.to_str().unwrap(),
37+
pc_target.to_str().unwrap(),
38+
"@Datadog_VERSION@",
39+
version,
40+
)?;
41+
42+
if *file == files[2] {
43+
file_replace(
44+
pc_origin.to_str().unwrap(),
45+
pc_target.to_str().unwrap(),
46+
"@Datadog_LIBRARIES@",
47+
native_libs,
48+
)?;
49+
}
50+
}
51+
Ok(())
52+
}
53+
454
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
555
#[cfg(all(target_os = "linux", target_env = "gnu"))]
656
mod linux;

builder/src/arch/musl.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use anyhow::Result;
45
use std::ffi::OsStr;
56
use std::process::Command;
67

@@ -56,3 +57,7 @@ pub fn strip_libraries(lib_path: &str) {
5657
}
5758

5859
pub fn add_additional_files(_lib_path: &str, _target_path: &OsStr) {}
60+
61+
pub fn add_pkg_config(crate_path: &str, target_path: &str, version: &str) -> Result<()> {
62+
super::generate_pkg_config(crate_path, target_path, version, NATIVE_LIBS)
63+
}

builder/src/arch/windows.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use anyhow::Result;
45
use std::ffi::OsStr;
56
use std::fs;
67
use std::path::PathBuf;
@@ -29,6 +30,12 @@ pub fn add_additional_files(lib_path: &str, target_path: &OsStr) {
2930
fs::copy(from_pdb, to_pdb).expect("unable to copy pdb file");
3031

3132
let from_imp: PathBuf = [lib_path, PROF_DLL_IMPORT_LIB_FFI].iter().collect();
32-
let to_imp: PathBuf = [target_path, OsStr::new(PROF_DLL_IMPORT_LIB_FFI)].iter().collect();
33+
let to_imp: PathBuf = [target_path, OsStr::new(PROF_DLL_IMPORT_LIB_FFI)]
34+
.iter()
35+
.collect();
3336
fs::copy(from_imp, to_imp).expect("unable to copy dll import lib");
3437
}
38+
39+
pub fn add_pkg_config(_crate_path: &str, _target_path: &str, _version: &str) -> Result<()> {
40+
Ok(())
41+
}

builder/src/profiling.rs

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use crate::arch;
55
use crate::module::Module;
6-
use crate::utils::{adjust_extern_symbols, file_replace, project_root, wait_for_success};
6+
use crate::utils::{adjust_extern_symbols, project_root, wait_for_success};
77
use anyhow::Result;
88
use serde::Deserialize;
99
use std::ffi::OsStr;
@@ -118,46 +118,11 @@ impl Profiling {
118118
}
119119

120120
fn add_pkg_config(&self) -> Result<()> {
121-
#[cfg(target_os = "windows")]
122-
return Ok(());
123-
124-
let files: [&str; 3] = [
125-
"datadog_profiling.pc",
126-
"datadog_profiling_with_rpath.pc",
127-
"datadog_profiling-static.pc",
128-
];
129-
130-
//Create directory
131-
let pc_dir = Path::new(self.target_pkconfig.as_ref());
132-
fs::create_dir_all(pc_dir).expect("Failed to create pkgconfig directory");
133-
134-
// Create files
135-
for file in files.iter() {
136-
let file_in = file.to_string() + ".in";
137-
138-
let mut pc_origin: PathBuf = project_root();
139-
pc_origin.push(CRATE_FOLDER);
140-
pc_origin.push(file_in);
141-
142-
let pc_target: PathBuf = [pc_dir.as_os_str(), OsStr::new(file)].iter().collect();
143-
144-
file_replace(
145-
pc_origin.to_str().unwrap(),
146-
pc_target.to_str().unwrap(),
147-
"@Datadog_VERSION@",
148-
&self.version,
149-
)?;
150-
151-
if *file == files[2] {
152-
file_replace(
153-
pc_origin.to_str().unwrap(),
154-
pc_target.to_str().unwrap(),
155-
"@Datadog_LIBRARIES@",
156-
arch::NATIVE_LIBS,
157-
)?;
158-
}
159-
}
160-
Ok(())
121+
arch::add_pkg_config(
122+
CRATE_FOLDER,
123+
self.target_pkconfig.as_ref(),
124+
self.version.as_ref(),
125+
)
161126
}
162127
}
163128

0 commit comments

Comments
 (0)