build.rs

 1use std::process::Command;
 2
 3fn main() {
 4    println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.15.7");
 5
 6    println!("cargo:rerun-if-env-changed=ZED_BUNDLE");
 7    if std::env::var("ZED_BUNDLE").ok().as_deref() == Some("true") {
 8        // Find WebRTC.framework in the Frameworks folder when running as part of an application bundle.
 9        println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path/../Frameworks");
10    } else {
11        // Find WebRTC.framework as a sibling of the executable when running outside of an application bundle.
12        println!("cargo:rustc-link-arg=-Wl,-rpath,@executable_path");
13    }
14
15    // Weakly link ReplayKit to ensure Zed can be used on macOS 10.15+.
16    println!("cargo:rustc-link-arg=-Wl,-weak_framework,ReplayKit");
17
18    // Seems to be required to enable Swift concurrency
19    println!("cargo:rustc-link-arg=-Wl,-rpath,/usr/lib/swift");
20
21    // Register exported Objective-C selectors, protocols, etc
22    println!("cargo:rustc-link-arg=-Wl,-ObjC");
23
24    // Populate git sha environment variable if git is available
25    println!("cargo:rerun-if-changed=.git/logs/HEAD");
26    if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() {
27        if output.status.success() {
28            let git_sha = String::from_utf8_lossy(&output.stdout);
29            let git_sha = git_sha.trim();
30
31            println!("cargo:rustc-env=ZED_COMMIT_SHA={git_sha}");
32
33            if let Ok(build_profile) = std::env::var("PROFILE") {
34                if build_profile == "release" {
35                    // This is currently the best way to make `cargo build ...`'s build script
36                    // to print something to stdout without extra verbosity.
37                    println!(
38                        "cargo:warning=Info: using '{git_sha}' hash for ZED_COMMIT_SHA env var"
39                    );
40                }
41            }
42        }
43    }
44}