Skip to repository content261 lines · 10.4 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T01:53:37.501Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
build.rs
1#![allow(clippy::disallowed_methods, reason = "build scripts are exempt")]
2use std::process::Command;
3
4fn main() {
5 #[cfg(target_os = "linux")]
6 {
7 // Add rpaths for libraries that webrtc-sys dlopens at runtime.
8 // This is mostly required for hosts with non-standard SO installation
9 // locations such as NixOS.
10 let dlopened_libs = ["libva", "libva-drm", "egl"];
11
12 let mut rpath_dirs = std::collections::BTreeSet::new();
13 for lib in &dlopened_libs {
14 if let Some(libdir) = pkg_config::get_variable(lib, "libdir").ok() {
15 rpath_dirs.insert(libdir);
16 } else {
17 eprintln!("zed build.rs: {lib} not found in pkg-config's path");
18 }
19 }
20
21 for dir in &rpath_dirs {
22 println!("cargo:rustc-link-arg=-Wl,-rpath,{dir}");
23 }
24 }
25
26 if cfg!(target_os = "macos") {
27 println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.15.7");
28
29 // Weakly link ReplayKit to ensure Zed can be used on macOS 10.15+.
30 println!("cargo:rustc-link-arg=-Wl,-weak_framework,ReplayKit");
31
32 // Seems to be required to enable Swift concurrency
33 println!("cargo:rustc-link-arg=-Wl,-rpath,/usr/lib/swift");
34
35 // Register exported Objective-C selectors, protocols, etc
36 println!("cargo:rustc-link-arg=-Wl,-ObjC");
37
38 // weak link to support Catalina
39 println!("cargo:rustc-link-arg=-Wl,-weak_framework,ScreenCaptureKit");
40 }
41
42 // Populate git sha environment variable if git is available
43 println!("cargo:rerun-if-changed=../../.git/logs/HEAD");
44 println!("cargo:rerun-if-env-changed=ZED_COMMIT_SHA");
45 println!(
46 "cargo:rustc-env=TARGET={}",
47 std::env::var("TARGET").unwrap()
48 );
49
50 let git_sha = match std::env::var("ZED_COMMIT_SHA").ok() {
51 Some(git_sha) => {
52 // In deterministic build environments such as Nix, we inject the commit sha into the build script.
53 Some(git_sha)
54 }
55 None => {
56 if let Some(output) = Command::new("git")
57 .args(["rev-parse", "HEAD"])
58 .output()
59 .ok()
60 && output.status.success()
61 {
62 let git_sha = String::from_utf8_lossy(&output.stdout);
63 Some(git_sha.trim().to_string())
64 } else {
65 None
66 }
67 }
68 };
69
70 if let Some(git_sha) = git_sha {
71 println!("cargo:rustc-env=ZED_COMMIT_SHA={git_sha}");
72
73 if let Some(build_identifier) = option_env!("GITHUB_RUN_NUMBER") {
74 println!("cargo:rustc-env=ZED_BUILD_ID={build_identifier}");
75 }
76
77 if let Ok(build_profile) = std::env::var("PROFILE")
78 && build_profile == "release"
79 {
80 // This is currently the best way to make `cargo build ...`'s build script
81 // to print something to stdout without extra verbosity.
82 println!("cargo::warning=Info: using '{git_sha}' hash for ZED_COMMIT_SHA env var");
83 }
84 }
85
86 if cfg!(windows) {
87 if cfg!(target_env = "msvc") {
88 // todo(windows): This is to avoid stack overflow. Remove it when solved.
89 println!("cargo:rustc-link-arg=/stack:{}", 8 * 1024 * 1024);
90 }
91
92 if cfg!(target_arch = "x86_64") || cfg!(target_arch = "aarch64") {
93 let out_dir = std::env::var("OUT_DIR").unwrap();
94 let out_dir: &std::path::Path = out_dir.as_ref();
95 let target_dir = std::path::Path::new(&out_dir)
96 .parent()
97 .and_then(|p| p.parent())
98 .and_then(|p| p.parent())
99 .expect("Failed to find target directory");
100
101 let conpty_dll_target = target_dir.join("conpty.dll");
102 let open_console_target = target_dir.join("OpenConsole.exe");
103
104 let conpty_url = "https://github.com/microsoft/terminal/releases/download/v1.24.10621.0/Microsoft.Windows.Console.ConPTY.1.24.260303001.nupkg";
105 let nupkg_path = out_dir.join("conpty.nupkg.zip");
106 let extract_dir = out_dir.join("conpty");
107
108 let download_script = format!(
109 "$ProgressPreference = 'SilentlyContinue'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '{}' -OutFile '{}'",
110 conpty_url,
111 nupkg_path.display()
112 );
113
114 let download_result = Command::new("powershell")
115 .args([
116 "-NoProfile",
117 "-NonInteractive",
118 "-Command",
119 &download_script,
120 ])
121 .output();
122
123 match download_result {
124 Ok(output) if output.status.success() => {
125 println!("Downloaded conpty nupkg successfully");
126
127 let extract_script = format!(
128 "$ProgressPreference = 'SilentlyContinue'; Expand-Archive -Path '{}' -DestinationPath '{}' -Force",
129 nupkg_path.display(),
130 extract_dir.display()
131 );
132
133 let extract_result = Command::new("powershell")
134 .args(["-NoProfile", "-NonInteractive", "-Command", &extract_script])
135 .output();
136
137 match extract_result {
138 Ok(output) if output.status.success() => {
139 let (conpty_dll_source, open_console_source) =
140 if cfg!(target_arch = "x86_64") {
141 (
142 extract_dir.join("runtimes/win-x64/native/conpty.dll"),
143 extract_dir
144 .join("build/native/runtimes/x64/OpenConsole.exe"),
145 )
146 } else {
147 (
148 extract_dir.join("runtimes/win-arm64/native/conpty.dll"),
149 extract_dir
150 .join("build/native/runtimes/arm64/OpenConsole.exe"),
151 )
152 };
153
154 match std::fs::copy(&conpty_dll_source, &conpty_dll_target) {
155 Ok(_) => {
156 println!("Copied conpty.dll to {}", conpty_dll_target.display())
157 }
158 Err(e) => println!(
159 "cargo::warning=Failed to copy conpty.dll from {}: {}",
160 conpty_dll_source.display(),
161 e
162 ),
163 }
164
165 match std::fs::copy(&open_console_source, &open_console_target) {
166 Ok(_) => println!(
167 "Copied OpenConsole.exe to {}",
168 open_console_target.display()
169 ),
170 Err(e) => println!(
171 "cargo::warning=Failed to copy OpenConsole.exe from {}: {}",
172 open_console_source.display(),
173 e
174 ),
175 }
176 }
177 Ok(output) => {
178 println!(
179 "cargo::warning=Failed to extract conpty nupkg: {}",
180 String::from_utf8_lossy(&output.stderr)
181 );
182 }
183 Err(e) => {
184 println!(
185 "cargo::warning=Failed to run PowerShell for extraction: {}",
186 e
187 );
188 }
189 }
190 }
191 Ok(output) => {
192 println!(
193 "cargo::warning=Failed to download conpty nupkg: {}",
194 String::from_utf8_lossy(&output.stderr)
195 );
196 }
197 Err(e) => {
198 println!(
199 "cargo::warning=Failed to run PowerShell for download: {}",
200 e
201 );
202 }
203 }
204 }
205
206 println!("cargo:rerun-if-env-changed=RELEASE_CHANNEL");
207 println!("cargo:rerun-if-env-changed=GITHUB_RUN_NUMBER");
208
209 #[cfg(windows)]
210 {
211 windows_resources::compile(false).expect("failed to compile Windows resources");
212 }
213 }
214
215 #[cfg(any(target_os = "linux", target_os = "freebsd"))]
216 prepare_app_icon_x11();
217}
218
219#[cfg(any(target_os = "linux", target_os = "freebsd"))]
220fn icon_path() -> std::path::PathBuf {
221 use std::str::FromStr;
222
223 let release_channel = option_env!("RELEASE_CHANNEL").unwrap_or("dev");
224 let channel = match release_channel {
225 "stable" => "",
226 "preview" => "-preview",
227 "nightly" => "-nightly",
228 "dev" => "-dev",
229 _ => "-dev",
230 };
231
232 #[cfg(windows)]
233 let icon = format!("resources/windows/app-icon{}.ico", channel);
234 #[cfg(not(windows))]
235 let icon = format!("resources/app-icon{}.png", channel);
236
237 std::path::PathBuf::from_str(&icon).unwrap()
238}
239
240#[cfg(any(target_os = "linux", target_os = "freebsd"))]
241fn prepare_app_icon_x11() {
242 use image::{ImageReader, imageops};
243 use std::env;
244 use std::path::Path;
245
246 let out_dir = env::var("OUT_DIR").unwrap();
247
248 let resized_image = ImageReader::open(icon_path())
249 .unwrap()
250 .decode()
251 .unwrap()
252 .resize(256, 256, imageops::FilterType::Lanczos3);
253
254 // name should match include_bytes! call in src/zed.rs
255 let icon_out_path = Path::new(&out_dir).join("app_icon.png");
256 resized_image.save(&icon_out_path).expect("saving app icon");
257
258 println!("cargo:rerun-if-env-changed=RELEASE_CHANNEL");
259 println!("cargo:rerun-if-changed={}", icon_path().to_string_lossy());
260}
261