Skip to content

Commit 41ecc6c

Browse files
committed
temp: testing changes
1 parent de059c9 commit 41ecc6c

File tree

6 files changed

+71
-13
lines changed

6 files changed

+71
-13
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ version-compare = "0.2"
2626
heck = "0.5"
2727
cfg-expr = { version = "0.17", features = ["targets"] }
2828
system-deps-binary = { path = "./binary", optional = true }
29+
cc = { version = "1.2", optional = true }
2930

3031
[dev-dependencies]
3132
lazy_static = "1"
3233
itertools = "0.13"
3334
assert_matches = "1.5"
3435

3536
[features]
36-
binary = [ "dep:system-deps-binary" ]
37+
default = [ "binary" ]
38+
binary = [ "dep:system-deps-binary", "dep:cc" ]
3739
gx = [ "system-deps-binary/gz" ]
3840
xz = [ "system-deps-binary/xz" ]
3941
zip = [ "system-deps-binary/zip" ]

binary/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
name = "system-deps-binary"
33
version = "0.1.0"
44
edition = "2021"
5-
links = "system-deps-binary"
65

76
[build-dependencies]
87
system-deps-meta = { path = "../meta" }

binary/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn paths() -> HashMap<String, Vec<PathBuf>> {
115115
let mut follow_list = HashMap::new();
116116

117117
// Global overrides from environment
118-
// TODO: This need to come first
118+
// TODO: Change this so the env set global url always is first in the list of paths
119119
if let Some(url) = env("SYSTEM_DEPS_BINARY_URL") {
120120
let checksum = env("SYSTEM_DEPS_BINARY_CHECKSUM");
121121
let pkg_paths = env("SYSTEM_DEPS_BINARY_PKG_PATHS");

meta/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn find_by_path(mut dir: PathBuf) -> Option<PathBuf> {
5050
/// Get the manifest from the project directory. This is **not** the directory
5151
/// where `system-deps` is cloned, it should point to the top level `Cargo.toml`
5252
/// file. This is needed to obtain metadata from all of dependencies, including
53-
/// those upstream of the package being compiled.
53+
/// those downstream of the package being compiled.
5454
///
5555
/// If the target directory is not a subfolder of the project it will not be
5656
/// possible to detect it automatically. In this case, the user will be asked

meta/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ fn check_cfg(lit: &str) -> Option<bool> {
4040

4141
/// Inserts values from b into a only if they don't already exist.
4242
/// TODO: This function could be a lot cleaner and it needs better error handling.
43+
/// The logic for merging values needs to handle more cases so during testing this will have to be rewritten.
44+
/// Additionally, make sure that only downstream crates can override the metadata.
4345
fn merge(a: &mut Value, b: Value) {
4446
match (a, b) {
4547
(a @ &mut Value::Object(_), Value::Object(b)) => {
@@ -66,7 +68,7 @@ fn merge(a: &mut Value, b: Value) {
6668
}
6769

6870
/// Recursively read dependency manifests to find metadata matching a key.
69-
/// The matching metadata is aggregated in a list, with upstream crates having priority
71+
/// The matching metadata is aggregated in a list, with downstream crates having priority
7072
/// for overwriting values. It will only read from the metadata sections matching the
7173
/// provided key.
7274
///
@@ -99,6 +101,8 @@ pub fn read_metadata(key: &str) -> Values {
99101
// Iterate through the dependency tree to visit all packages
100102
let mut visited: HashSet<&str> = packages.iter().map(|p| p.name.as_str()).collect();
101103
while let Some(pkg) = packages.pop_front() {
104+
// TODO: Optional packages
105+
102106
for dep in &pkg.dependencies {
103107
match dep.kind {
104108
DependencyKind::Normal | DependencyKind::Build => {}

src/lib.rs

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,54 @@ impl Config {
836836
let mut libraries = self.probe_pkg_config()?;
837837
libraries.override_from_flags(&self.env);
838838

839+
// TODO: Generate shared library
840+
// This doesn't work, multiple symbols
841+
//#[cfg(feature = "binary")]
842+
//if libraries.libs.contains_key("gstreamer_1_0") {
843+
// let out_dir = env::var("OUT_DIR").unwrap();
844+
// let mut library = Library::from_env_variables("gstreamer-full");
845+
//
846+
// let mut cc = cc::Build::new();
847+
//
848+
// cc.shared_flag(true).flag("-Wl,--whole-archive");
849+
//
850+
// for (_, lib) in libraries.libs.drain() {
851+
// lib.link_paths.iter().for_each(|l| {
852+
// cc.flag(format!("-L{}", l.to_string_lossy()));
853+
// });
854+
// lib.libs.iter().for_each(|l| {
855+
// if lib.statik && l.is_static_available {
856+
// cc.flag("-Wl,-Bstatic");
857+
// } else {
858+
// cc.flag("-Wl,-Bdynamic");
859+
// }
860+
// cc.flag(format!("-l{}", l.name));
861+
// });
862+
// lib.ld_args.iter().for_each(|f| {
863+
// cc.flag(f.join(" "));
864+
// });
865+
//
866+
// library.include_paths.extend(lib.include_paths);
867+
// }
868+
//
869+
// let lib_path = format!("{}/libgstreamer-full.so", out_dir);
870+
// library.libs = vec![InternalLib::new("gstreamer-full".into(), true)];
871+
// library.link_paths = vec![PathBuf::from(out_dir)];
872+
//
873+
// let mut cmd = cc
874+
// .flag("-Wl,--no-whole-archive")
875+
// .flag("-Wl,-Bdynamic")
876+
// .flag("-o")
877+
// .flag(lib_path)
878+
// .get_compiler()
879+
// .to_command();
880+
//
881+
// println!("cargo:warning={:?}", cmd);
882+
// cmd.status().unwrap();
883+
//
884+
// libraries.libs.insert("gstreamer-full".into(), library);
885+
//}
886+
839887
Ok(libraries)
840888
}
841889

@@ -934,9 +982,10 @@ impl Config {
934982
combined_pkg_config_path.extend_from_slice(&pkg_config_path);
935983

936984
// should the lib be statically linked?
937-
let statik = self
938-
.env
939-
.has_value(&EnvVariable::new_link(Some(name)), "static")
985+
let statik = cfg!(feature = "binary")
986+
|| self
987+
.env
988+
.has_value(&EnvVariable::new_link(Some(name)), "static")
940989
|| self.env.has_value(&EnvVariable::new_link(None), "static");
941990

942991
let mut library = if self.env.contains(&EnvVariable::new_no_pkg_config(name)) {
@@ -1261,25 +1310,29 @@ impl Library {
12611310
F: FnOnce() -> Result<R, pkg_config::Error>,
12621311
{
12631312
// Save current PKG_CONFIG_PATH, so we can restore it
1264-
let old = env::var("PKG_CONFIG_PATH");
1265-
let old_paths = old
1313+
let prev = env::var("PKG_CONFIG_PATH").ok();
1314+
let prev_paths = prev
12661315
.as_ref()
12671316
.map(env::split_paths)
1268-
.unwrap()
1317+
.into_iter()
1318+
.flatten()
12691319
.collect::<Vec<_>>();
12701320

12711321
let paths = env::join_paths(
12721322
pkg_config_dir
12731323
.iter()
12741324
.map(|p| p.as_ref())
1275-
.chain(old_paths.iter().map(|p| p.as_os_str())),
1325+
.chain(prev_paths.iter().map(|p| p.as_os_str())),
12761326
)
12771327
.unwrap();
1328+
12781329
env::set_var("PKG_CONFIG_PATH", paths);
12791330

12801331
let res = f();
12811332

1282-
env::set_var("PKG_CONFIG_PATH", old.unwrap_or_else(|_| "".into()));
1333+
if let Some(prev) = prev {
1334+
env::set_var("PKG_CONFIG_PATH", prev);
1335+
}
12831336

12841337
res
12851338
}

0 commit comments

Comments
 (0)