1use std::process::Command;
2
3fn main() {
4 if cfg!(target_os = "macos") {
5 println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.15.7");
6
7 // Weakly link ReplayKit to ensure Zed can be used on macOS 10.15+.
8 println!("cargo:rustc-link-arg=-Wl,-weak_framework,ReplayKit");
9
10 // Seems to be required to enable Swift concurrency
11 println!("cargo:rustc-link-arg=-Wl,-rpath,/usr/lib/swift");
12
13 // Register exported Objective-C selectors, protocols, etc
14 println!("cargo:rustc-link-arg=-Wl,-ObjC");
15 }
16
17 // Populate git sha environment variable if git is available
18 println!("cargo:rerun-if-changed=../../.git/logs/HEAD");
19 println!(
20 "cargo:rustc-env=TARGET={}",
21 std::env::var("TARGET").unwrap()
22 );
23 if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() {
24 if output.status.success() {
25 let git_sha = String::from_utf8_lossy(&output.stdout);
26 let git_sha = git_sha.trim();
27
28 println!("cargo:rustc-env=ZED_COMMIT_SHA={git_sha}");
29
30 if let Ok(build_profile) = std::env::var("PROFILE") {
31 if build_profile == "release" {
32 // This is currently the best way to make `cargo build ...`'s build script
33 // to print something to stdout without extra verbosity.
34 println!(
35 "cargo:warning=Info: using '{git_sha}' hash for ZED_COMMIT_SHA env var"
36 );
37 }
38 }
39 }
40 }
41
42 #[cfg(target_os = "windows")]
43 {
44 #[cfg(target_env = "msvc")]
45 {
46 // todo(windows): This is to avoid stack overflow. Remove it when solved.
47 println!("cargo:rustc-link-arg=/stack:{}", 8 * 1024 * 1024);
48 }
49
50 let icon = std::path::Path::new("resources/windows/app-icon.ico");
51 println!("cargo:rerun-if-changed={}", icon.display());
52
53 let mut res = winresource::WindowsResource::new();
54
55 // Depending on the security applied to the computer, winresource might fail
56 // fetching the RC path. Therefore, we add a way to explicitly specify the
57 // toolkit path, allowing winresource to use a valid RC path.
58 if let Some(explicit_rc_toolkit_path) = std::env::var("ZED_RC_TOOLKIT_PATH").ok() {
59 res.set_toolkit_path(explicit_rc_toolkit_path.as_str());
60 }
61 res.set_icon(icon.to_str().unwrap());
62 res.set("FileDescription", "Zed");
63 res.set("ProductName", "Zed");
64
65 if let Err(e) = res.compile() {
66 eprintln!("{}", e);
67 std::process::exit(1);
68 }
69 }
70}