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        // Weakly link ReplayKit to ensure Zed can be used on macOS 10.15+.
10        println!("cargo:rustc-link-arg=-Wl,-weak_framework,ReplayKit");
11
12        // Seems to be required to enable Swift concurrency
13        println!("cargo:rustc-link-arg=-Wl,-rpath,/usr/lib/swift");
14
15        // Register exported Objective-C selectors, protocols, etc
16        println!("cargo:rustc-link-arg=-Wl,-ObjC");
17    }
18
19    // Populate git sha environment variable if git is available
20    println!("cargo:rerun-if-changed=../../.git/logs/HEAD");
21    println!(
22        "cargo:rustc-env=TARGET={}",
23        std::env::var("TARGET").unwrap()
24    );
25    if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() {
26        if output.status.success() {
27            let git_sha = String::from_utf8_lossy(&output.stdout);
28            let git_sha = git_sha.trim();
29
30            println!("cargo:rustc-env=ZED_COMMIT_SHA={git_sha}");
31
32            if let Ok(build_profile) = std::env::var("PROFILE") {
33                if build_profile == "release" {
34                    // This is currently the best way to make `cargo build ...`'s build script
35                    // to print something to stdout without extra verbosity.
36                    println!(
37                        "cargo:warning=Info: using '{git_sha}' hash for ZED_COMMIT_SHA env var"
38                    );
39                }
40            }
41        }
42    }
43
44    #[cfg(target_os = "windows")]
45    {
46        #[cfg(target_env = "msvc")]
47        {
48            // todo(windows): This is to avoid stack overflow. Remove it when solved.
49            println!("cargo:rustc-link-arg=/stack:{}", 8 * 1024 * 1024);
50        }
51    }
52}