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 // weak link to support Catalina
17 println!("cargo:rustc-link-arg=-Wl,-weak_framework,ScreenCaptureKit");
18 }
19
20 // Populate git sha environment variable if git is available
21 println!("cargo:rerun-if-changed=../../.git/logs/HEAD");
22 println!(
23 "cargo:rustc-env=TARGET={}",
24 std::env::var("TARGET").unwrap()
25 );
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
45 #[cfg(target_os = "windows")]
46 {
47 #[cfg(target_env = "msvc")]
48 {
49 // todo(windows): This is to avoid stack overflow. Remove it when solved.
50 println!("cargo:rustc-link-arg=/stack:{}", 8 * 1024 * 1024);
51 }
52
53 let release_channel = option_env!("RELEASE_CHANNEL").unwrap_or("dev");
54 let icon = match release_channel {
55 "stable" => "resources/windows/app-icon.ico",
56 "preview" => "resources/windows/app-icon-preview.ico",
57 "nightly" => "resources/windows/app-icon-nightly.ico",
58 "dev" => "resources/windows/app-icon-dev.ico",
59 _ => "resources/windows/app-icon-dev.ico",
60 };
61 let icon = std::path::Path::new(icon);
62
63 println!("cargo:rerun-if-env-changed=RELEASE_CHANNEL");
64 println!("cargo:rerun-if-changed={}", icon.display());
65
66 let mut res = winresource::WindowsResource::new();
67
68 // Depending on the security applied to the computer, winresource might fail
69 // fetching the RC path. Therefore, we add a way to explicitly specify the
70 // toolkit path, allowing winresource to use a valid RC path.
71 if let Some(explicit_rc_toolkit_path) = std::env::var("ZED_RC_TOOLKIT_PATH").ok() {
72 res.set_toolkit_path(explicit_rc_toolkit_path.as_str());
73 }
74 res.set_icon(icon.to_str().unwrap());
75 res.set("FileDescription", "Zed");
76 res.set("ProductName", "Zed");
77
78 if let Err(e) = res.compile() {
79 eprintln!("{}", e);
80 std::process::exit(1);
81 }
82 }
83}