From 592692c004f29c85f235662c8a5e9c11d69472c1 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 3 Jan 2023 13:41:31 -0500 Subject: [PATCH] Include Swift in rpath on linux --- Cargo.toml | 4 ++++ build.rs | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 65995ed..ab09101 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[build-dependencies] +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" + [dependencies] activitystreams = "0.7.0-alpha.22" activitystreams-ext = "0.1.0-alpha.3" diff --git a/build.rs b/build.rs index 7609593..4ca91d5 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,42 @@ -// generated by `sqlx migrate build-script` +use serde::Deserialize; +use std::process::Command; + fn main() { // trigger recompilation when a new migration is added println!("cargo:rerun-if-changed=migrations"); -} \ No newline at end of file + + let target = get_swift_target_info(); + if target.target.unversioned_triple.contains("linux") { + target.paths.runtime_library_paths.iter().for_each(|path| { + println!("cargo:rustc-link-arg=-Wl,-rpath={}", path); + }); + } +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct SwiftTargetInfo { + pub unversioned_triple: String, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct SwiftPaths { + pub runtime_library_paths: Vec, +} + +#[derive(Debug, Deserialize)] +pub struct SwiftTarget { + pub target: SwiftTargetInfo, + pub paths: SwiftPaths, +} + +pub fn get_swift_target_info() -> SwiftTarget { + let swift_target_info_str = Command::new("swift") + .args(&["-print-target-info"]) + .output() + .unwrap() + .stdout; + + serde_json::from_slice(&swift_target_info_str).unwrap() +}