about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/office/espanso/inject-wx-on-darwin.patch
blob: 34b711211927470c1c4eb92f537ef1b77a1e8e2b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
From 6a7400c20831c5ff502c7336d6db2be743f156be Mon Sep 17 00:00:00 2001
From: Nikola Knezevic <nikola.knezevic@imc.com>
Date: Tue, 16 Aug 2022 22:28:46 +0200
Subject: [PATCH] Build using system wx on darwin

---
 espanso-modulo/build.rs | 174 ++++------------------------------------
 1 file changed, 17 insertions(+), 157 deletions(-)

diff --git a/espanso-modulo/build.rs b/espanso-modulo/build.rs
index b8b889a..5d972ec 100644
--- a/espanso-modulo/build.rs
+++ b/espanso-modulo/build.rs
@@ -156,161 +156,6 @@ fn build_native() {
   );
 }
 
-#[cfg(target_os = "macos")]
-fn build_native() {
-  use std::process::Command;
-
-  let project_dir =
-    PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").expect("missing CARGO_MANIFEST_DIR"));
-  let wx_archive = project_dir.join("vendor").join(WX_WIDGETS_ARCHIVE_NAME);
-  if !wx_archive.is_file() {
-    panic!("could not find wxWidgets archive!");
-  }
-
-  let out_dir = if let Ok(out_path) = std::env::var(WX_WIDGETS_BUILD_OUT_DIR_ENV_NAME) {
-    println!(
-      "detected wxWidgets build output directory override: {}",
-      out_path
-    );
-    let path = PathBuf::from(out_path);
-    std::fs::create_dir_all(&path).expect("unable to create wxWidgets out dir");
-    path
-  } else {
-    PathBuf::from(std::env::var("OUT_DIR").expect("missing OUT_DIR"))
-  };
-  let out_wx_dir = out_dir.join("wx");
-  println!("wxWidgets will be compiled into: {}", out_wx_dir.display());
-
-  let target_arch = match std::env::var("CARGO_CFG_TARGET_ARCH")
-    .expect("unable to read target arch")
-    .as_str()
-  {
-    "x86_64" => "x86_64",
-    "aarch64" => "arm64",
-    arch => panic!("unsupported arch {}", arch),
-  };
-
-  let should_use_ci_m1_workaround =
-    std::env::var("CI").unwrap_or_default() == "true" && target_arch == "arm64";
-
-  if !out_wx_dir.is_dir() {
-    // Extract the wxWidgets archive
-    let wx_archive =
-      std::fs::File::open(&wx_archive).expect("unable to open wxWidgets source archive");
-    let mut archive = zip::ZipArchive::new(wx_archive).expect("unable to read wxWidgets archive");
-    archive
-      .extract(&out_wx_dir)
-      .expect("unable to extract wxWidgets source dir");
-
-    // Compile wxWidgets
-    let build_dir = out_wx_dir.join("build-cocoa");
-    std::fs::create_dir_all(&build_dir).expect("unable to create build-cocoa directory");
-
-    let mut handle = if should_use_ci_m1_workaround {
-      // Because of a configuration problem on the GitHub CI pipeline,
-      // we need to use a series of workarounds to build for M1 machines.
-      // See: https://github.com/actions/virtual-environments/issues/3288#issuecomment-830207746
-      Command::new(out_wx_dir.join("configure"))
-        .current_dir(build_dir.to_string_lossy().to_string())
-        .args(&[
-          "--disable-shared",
-          "--without-libtiff",
-          "--without-liblzma",
-          "--with-libjpeg=builtin",
-          "--with-libpng=builtin",
-          "--enable-universal-binary=arm64,x86_64",
-        ])
-        .spawn()
-        .expect("failed to execute configure")
-    } else {
-      Command::new(out_wx_dir.join("configure"))
-        .current_dir(build_dir.to_string_lossy().to_string())
-        .args(&[
-          "--disable-shared",
-          "--without-libtiff",
-          "--without-liblzma",
-          "--with-libjpeg=builtin",
-          "--with-libpng=builtin",
-          &format!("--enable-macosx_arch={}", target_arch),
-        ])
-        .spawn()
-        .expect("failed to execute configure")
-    };
-
-    if !handle
-      .wait()
-      .expect("unable to wait for configure command")
-      .success()
-    {
-      panic!("configure returned non-zero exit code!");
-    }
-
-    let mut handle = Command::new("make")
-      .current_dir(build_dir.to_string_lossy().to_string())
-      .args(&["-j8"])
-      .spawn()
-      .expect("failed to execute make");
-    if !handle
-      .wait()
-      .expect("unable to wait for make command")
-      .success()
-    {
-      panic!("make returned non-zero exit code!");
-    }
-  }
-
-  // Make sure wxWidgets is compiled
-  if !out_wx_dir.join("build-cocoa").is_dir() {
-    panic!("wxWidgets is not compiled correctly, missing 'build-cocoa/' directory")
-  }
-
-  // If using the M1 CI workaround, convert all the universal libraries to arm64 ones
-  // This is needed until https://github.com/rust-lang/rust/issues/55235 is fixed
-  if should_use_ci_m1_workaround {
-    convert_fat_libraries_to_arm(&out_wx_dir.join("build-cocoa").join("lib"));
-    convert_fat_libraries_to_arm(&out_wx_dir.join("build-cocoa"));
-  }
-
-  let config_path = out_wx_dir.join("build-cocoa").join("wx-config");
-  let cpp_flags = get_cpp_flags(&config_path);
-
-  let mut build = cc::Build::new();
-  build
-    .cpp(true)
-    .file("src/sys/form/form.cpp")
-    .file("src/sys/common/common.cpp")
-    .file("src/sys/search/search.cpp")
-    .file("src/sys/wizard/wizard.cpp")
-    .file("src/sys/wizard/wizard_gui.cpp")
-    .file("src/sys/welcome/welcome.cpp")
-    .file("src/sys/welcome/welcome_gui.cpp")
-    .file("src/sys/textview/textview.cpp")
-    .file("src/sys/textview/textview_gui.cpp")
-    .file("src/sys/troubleshooting/troubleshooting.cpp")
-    .file("src/sys/troubleshooting/troubleshooting_gui.cpp")
-    .file("src/sys/common/mac.mm");
-  build.flag("-std=c++17");
-
-  for flag in cpp_flags {
-    build.flag(&flag);
-  }
-
-  build.compile("espansomodulosys");
-
-  // Render linker flags
-
-  generate_linker_flags(&config_path);
-
-  // On (older) OSX we need to link against the clang runtime,
-  // which is hidden in some non-default path.
-  //
-  // More details at https://github.com/alexcrichton/curl-rust/issues/279.
-  if let Some(path) = macos_link_search_path() {
-    println!("cargo:rustc-link-lib=clang_rt.osx");
-    println!("cargo:rustc-link-search={}", path);
-  }
-}
-
 #[cfg(target_os = "macos")]
 fn convert_fat_libraries_to_arm(lib_dir: &Path) {
   for entry in
@@ -440,12 +285,17 @@ fn macos_link_search_path() -> Option<String> {
   None
 }
 
+#[cfg(not(target_os = "macos"))]
+fn macos_link_search_path() -> Option<String> {
+    return None
+}
+
 // TODO: add documentation for linux
 // Install wxWidgets:
 // sudo apt install libwxgtk3.0-0v5 libwxgtk3.0-dev
 //
 // cargo run
-#[cfg(target_os = "linux")]
+#[cfg(not(target_os = "windows"))]
 fn build_native() {
   // Make sure wxWidgets is installed
   // Depending on the installation package, the 'wx-config' command might also be available as 'wx-config-gtk3',
@@ -483,7 +333,8 @@ fn build_native() {
     .file("src/sys/textview/textview.cpp")
     .file("src/sys/textview/textview_gui.cpp")
     .file("src/sys/troubleshooting/troubleshooting.cpp")
-    .file("src/sys/troubleshooting/troubleshooting_gui.cpp");
+    .file("src/sys/troubleshooting/troubleshooting_gui.cpp")
+    .file("src/sys/common/mac.mm");
   build.flag("-std=c++17");
 
   for flag in cpp_flags {
@@ -495,6 +346,15 @@ fn build_native() {
   // Render linker flags
 
   generate_linker_flags(&config_path);
+
+  // On (older) OSX we need to link against the clang runtime,
+  // which is hidden in some non-default path.
+  //
+  // More details at https://github.com/alexcrichton/curl-rust/issues/279.
+  if let Some(path) = macos_link_search_path() {
+    println!("cargo:rustc-link-lib=clang_rt.osx");
+    println!("cargo:rustc-link-search={}", path);
+  }
 }
 
 fn main() {
-- 
2.37.1