build.rs

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