macOS build: universal app for Apple Silicon and Intel, macOS 11+ #23

Merged
noah merged 1 commits from macos-build into main 2026-11-03 14:41:25 -07:00
12 changed files with 495 additions and 35 deletions
+3 -1
View File
@@ -32,7 +32,9 @@ uses offline fixtures and does not contact hardware.
Windows 10/11 builds are cross-compiled on Linux (`scripts/build-wx-windows.sh`,
then `scripts/build-gui-windows.sh`) and attached to every release as a
self-contained `alkane-toolkit.exe`; see [docs/windows.md](docs/windows.md).
macOS is not built.
macOS builds run on a Mac (`scripts/build-wx-macos.sh`, then
`scripts/build-gui-macos.sh`) and produce one universal app for Apple Silicon
and Intel, macOS 11 or later; see [docs/macos.md](docs/macos.md).
## Current scope
+109
View File
@@ -0,0 +1,109 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
"""Package the universal macOS build as an app bundle, for release.
package-macos.py VERSION BINARY OUT_DIR
BINARY is the universal (arm64 + x86_64) alkane-toolkit executable made by
scripts/build-gui-macos.sh. Writes
dist/alkane-toolkit-vVERSION-macos-universal.zip holding "Alkane Toolkit.app",
LICENSE and README.txt, and prints its path. Runs on macOS (lipo, codesign,
ditto).
The bundle is ad-hoc signed only (Apple Silicon refuses to run unsigned
code); it is not signed with a Developer ID or notarized, so Gatekeeper asks
the user to confirm the first launch. README.txt says how.
"""
import pathlib
import plistlib
import shutil
import subprocess
import sys
import tempfile
ROOT = pathlib.Path(__file__).resolve().parents[1]
APP = "Alkane Toolkit.app"
BUNDLE_ID = "re.bluefla.alkane-toolkit"
MIN_MACOS = "11.0"
def run(*args: str) -> str:
return subprocess.run(args, check=True, capture_output=True, text=True).stdout
def build_app(version: str, binary: pathlib.Path, dest: pathlib.Path) -> pathlib.Path:
archs = run("lipo", "-archs", str(binary)).split()
if sorted(archs) != ["arm64", "x86_64"]:
sys.exit(f"{binary} is not a universal arm64 + x86_64 binary: {archs}")
app = dest / APP
macos = app / "Contents" / "MacOS"
resources = app / "Contents" / "Resources"
macos.mkdir(parents=True)
resources.mkdir()
shutil.copy2(binary, macos / "alkane-toolkit")
shutil.copy2(ROOT / "crates/alkane-gui/macos/alkane-toolkit.icns", resources)
info = {
"CFBundleName": "Alkane Toolkit",
"CFBundleDisplayName": "Alkane Toolkit",
"CFBundleIdentifier": BUNDLE_ID,
"CFBundleExecutable": "alkane-toolkit",
"CFBundleIconFile": "alkane-toolkit",
"CFBundlePackageType": "APPL",
"CFBundleShortVersionString": version,
"CFBundleVersion": version,
"CFBundleInfoDictionaryVersion": "6.0",
"LSMinimumSystemVersion": MIN_MACOS,
"NSHighResolutionCapable": True,
"NSPrincipalClass": "NSApplication",
# The scanner talks to miners on the local network.
"NSLocalNetworkUsageDescription":
"Alkane Toolkit scans your local network to find and manage miners.",
"NSHumanReadableCopyright":
"Copyright (c) 2026 BlueFlare Energy Solutions Inc. (MIT License)",
}
with open(app / "Contents" / "Info.plist", "wb") as fh:
plistlib.dump(info, fh)
(app / "Contents" / "PkgInfo").write_text("APPL????")
# Ad-hoc signature over the whole bundle (the linker's per-slice
# signatures do not cover Info.plist or the resources).
run("codesign", "--force", "--sign", "-", "--timestamp=none", str(app))
run("codesign", "--verify", "--strict", str(app))
return app
def release(version: str, binary: str, out_dir: str) -> None:
name = f"alkane-toolkit-v{version}-macos-universal"
out = pathlib.Path(out_dir).resolve() / f"{name}.zip"
out.parent.mkdir(parents=True, exist_ok=True)
readme = (
f"alkane-toolkit v{version} (macOS, Apple Silicon and Intel)\n"
"\n"
f"Runs on macOS {MIN_MACOS} (Big Sur) or later. Drag \"Alkane Toolkit\"\n"
"to Applications, then open it.\n"
"\n"
"The app is not notarized by Apple, so the first launch is blocked\n"
"with a warning. To allow it once:\n"
" - macOS 15 or later: try to open it, then System Settings >\n"
" Privacy & Security > \"Open Anyway\" for Alkane Toolkit.\n"
" - macOS 11 to 14: Control-click the app, choose Open, then Open.\n"
"Or, in Terminal: xattr -dr com.apple.quarantine \"/Applications/Alkane Toolkit.app\"\n"
"\n"
"Settings are stored in ~/.config/alkane-toolkit/.\n"
"Manual: https://blueflare.gitea.bluefla.re/alkane-toolkit/manual/\n"
)
with tempfile.TemporaryDirectory(prefix="alkane-macos-") as tmp:
folder = pathlib.Path(tmp) / name
folder.mkdir()
build_app(version, pathlib.Path(binary), folder)
shutil.copy2(ROOT / "LICENSE", folder / "LICENSE")
(folder / "README.txt").write_text(readme)
out.unlink(missing_ok=True)
run("ditto", "-c", "-k", "--keepParent", str(folder), str(out))
print(out)
if __name__ == "__main__":
if len(sys.argv) != 4:
sys.exit(__doc__)
release(*sys.argv[1:])
Binary file not shown.
+34
View File
@@ -0,0 +1,34 @@
#!/bin/sh
# Regenerate alkane-toolkit.icns (the macOS app icon) from the in-repo
# microchip glyph: the same white chip on a rounded amber tile as the Windows
# icon, at the sizes macOS asks for (16-1024 px). Needs rsvg-convert,
# ImageMagick and python3; the .icns is committed, so a build never runs this.
set -e
cd "$(dirname "$0")"
GLYPH=../assets/icons/microchip-solid-full.svg
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' 0
sed 's/currentColor/#ffffff/g; s/<svg /<svg fill="#ffffff" /' "$GLYPH" > "$TMP/glyph.svg"
for s in 16 32 64 128 256 512 1024; do
# Apple's grid: the tile fills ~80% of the canvas, centred.
t=$((s * 80 / 100)); m=$(((s - t) / 2)); r=$((t * 22 / 100))
g=$((t * 60 / 100)); o=$(((s - g) / 2))
rsvg-convert -w "$g" -h "$g" "$TMP/glyph.svg" -o "$TMP/g$s.png"
convert -size "${s}x${s}" xc:none -fill '#d9822b' \
-draw "roundrectangle $m,$m $((m + t - 1)),$((m + t - 1)) $r,$r" \
"$TMP/g$s.png" -geometry "+$o+$o" -composite "PNG32:$TMP/i$s.png"
done
python3 - "$TMP" alkane-toolkit.icns <<'PY'
import pathlib, struct, sys
tmp, out = pathlib.Path(sys.argv[1]), sys.argv[2]
# ICNS element types that hold PNG data, by pixel size.
types = [("icp4", 16), ("icp5", 32), ("icp6", 64), ("ic07", 128), ("ic08", 256),
("ic09", 512), ("ic10", 1024), ("ic11", 32), ("ic12", 64), ("ic13", 256),
("ic14", 512)]
body = b""
for kind, size in types:
data = (tmp / f"i{size}.png").read_bytes()
body += kind.encode() + struct.pack(">I", len(data) + 8) + data
pathlib.Path(out).write_bytes(b"icns" + struct.pack(">I", len(body) + 8) + body)
PY
echo "wrote $(pwd)/alkane-toolkit.icns"
+62
View File
@@ -0,0 +1,62 @@
# macOS
The macOS build is one universal app, `Alkane Toolkit.app`, that runs natively
on Apple Silicon and Intel Macs with macOS 11 (Big Sur) or later. It ships as
`alkane-toolkit-vX.Y.Z-macos-universal.zip`, holding the app, `LICENSE` and a
`README.txt`.
## Using it
- Settings live in `~/.config/alkane-toolkit`, the same files as on Linux.
- SSH actions use the system `ssh`; HTTP actions use the system `curl`.
- The app is ad-hoc signed but not notarized, so macOS blocks the first launch.
On macOS 15 or later, try to open it, then choose **Open Anyway** in
System Settings > Privacy & Security. On macOS 11 to 14, Control-click the
app and choose **Open**. Or clear the quarantine flag once:
`xattr -dr com.apple.quarantine "/Applications/Alkane Toolkit.app"`.
- The first scan asks for permission to find devices on the local network
(macOS 15 and later). Scanning needs it.
- Offline demo: `ALKANE_FAKE_SCAN=1 "/Applications/Alkane Toolkit.app/Contents/MacOS/alkane-toolkit"`.
## Building
macOS builds only on a Mac. It needs the Xcode Command Line Tools
(`xcode-select --install`) and rustup with both Apple targets:
```sh
rustup target add aarch64-apple-darwin x86_64-apple-darwin
scripts/build-wx-macos.sh # once: universal static wxOSX 3.3.3 in ~/.cache/wx-3.3.3-macos
scripts/build-gui-macos.sh # both slices, merged with lipo
python3 ci/package-macos.py X.Y.Z target/universal-apple-darwin/release/alkane-toolkit dist
```
`build-wx-macos.sh` builds wxWidgets once for arm64 and x86_64 together, with
wx's bundled image, zlib, regex and expat libraries, so the app links only
against system frameworks. `build-gui-macos.sh` builds each Rust target
against that prefix and merges them. `package-macos.py` writes the bundle
(Info.plist, icon), ad-hoc signs it and zips it with `ditto`.
To test on the Mac:
```sh
ALKANE_SELFTEST=1 target/universal-apple-darwin/release/alkane-toolkit # headless UI self-test
cargo test --release --offline --target aarch64-apple-darwin --workspace --exclude wx-rs
```
The self-test opens a window briefly, so it needs a logged-in desktop
session. Running the x86_64 slice on Apple Silicon needs Rosetta 2.
## Why macOS 11
Current Xcode SDKs ship a libc++ that supports macOS 11 and later only;
building for an older target compiles, but the app could fail at run time on
the older system. macOS 11 is also the first release for Apple Silicon. Older
Intel Macs would need a build with an older SDK.
## Notes for the bridge
wxOSX reports logical (point) sizes, like the GTK and MSW bridges; the
bridge never scales to physical pixels. wxOSX's Objective-C uses
`@available`, so `build.rs` links clang's compiler runtime
(`libclang_rt.osx.a`), which rustc's link does not include by itself. Both
are wx-rs patch `0009`.
+11
View File
@@ -14,6 +14,7 @@ Get the latest release from the
|---|---|---|
| Windows 10 and 11 (x86_64) | `alkane-toolkit-vX.Y.Z-windows-x86_64.zip` | One signed `alkane-toolkit.exe`; nothing to install |
| Linux (x86_64) | `alkane-toolkit-vX.Y.Z-linux-x86_64.tar.gz` | One binary; needs GTK 3 (`sudo apt install libgtk-3-0`) |
| macOS 11 or later (Apple Silicon and Intel) | `alkane-toolkit-vX.Y.Z-macos-universal.zip` | One app; not notarized, so confirm the first launch |
### Windows
@@ -23,6 +24,16 @@ Get the latest release from the
the verified publisher. To check the signature yourself, right-click the exe,
choose **Properties** and open **Digital Signatures**.
### macOS
1. Download the zip and open it; drag **Alkane Toolkit** to Applications.
2. Open it. The app is not notarized, so macOS blocks the first launch:
- macOS 15 or later: open **System Settings > Privacy & Security** and
choose **Open Anyway** for Alkane Toolkit.
- macOS 11 to 14: Control-click the app, choose **Open**, then **Open**.
3. When asked, allow it to find devices on your local network. Scanning
needs this.
### Linux
```sh
+25 -6
View File
@@ -1,9 +1,28 @@
#!/bin/sh
# Build the alkane-toolkit GUI on macOS.
# wx-rs upstream supports macOS: its build.rs clones/builds wx 3.2.2.1 into
# ./dist (osx-release-build) on first build. Requires Xcode Command Line
# Tools. Run this ON a Mac - macOS cannot be linked from Linux.
# Build the alkane-toolkit GUI on macOS as one universal binary.
#
# scripts/build-gui-macos.sh [extra cargo build args]
# -> target/universal-apple-darwin/release/alkane-toolkit (arm64 + x86_64)
#
# Needs the Xcode Command Line Tools, rustup with the aarch64-apple-darwin and
# x86_64-apple-darwin targets, and the universal static wx prefix from
# scripts/build-wx-macos.sh (WX_MACOS_PREFIX, default ~/.cache/wx-3.3.3-macos).
# Each target is built separately against that prefix, then the two slices
# are merged with lipo. MACOSX_DEPLOYMENT_TARGET matches the wx build.
set -e
cd "$(dirname -- "$0")/.."
cargo build --release -p alkane-gui
echo "binary: target/release/alkane-toolkit (app bundle packaging is follow-up)"
PREFIX="${WX_MACOS_PREFIX:-$HOME/.cache/wx-3.3.3-macos}"
[ -x "$PREFIX/bin/wx-config" ] || {
echo "no wx prefix at $PREFIX; run scripts/build-wx-macos.sh first" >&2; exit 1; }
export WX_RS_WXCONFIG="$PREFIX/bin/wx-config"
export MACOSX_DEPLOYMENT_TARGET="${MACOSX_MIN:-11.0}"
for target in aarch64-apple-darwin x86_64-apple-darwin; do
cargo build --release --offline --locked -p alkane-gui --target "$target" "$@"
done
out=target/universal-apple-darwin/release
mkdir -p "$out"
lipo -create -output "$out/alkane-toolkit" \
target/aarch64-apple-darwin/release/alkane-toolkit \
target/x86_64-apple-darwin/release/alkane-toolkit
lipo -info "$out/alkane-toolkit"
echo "binary: $out/alkane-toolkit"
+43
View File
@@ -0,0 +1,43 @@
#!/bin/sh
# Build the vendored wxWidgets 3.3.3 for macOS: wxOSX/Cocoa, static,
# monolithic, and universal (arm64 + x86_64) so one prefix serves both Rust
# targets. Run on a Mac with the Xcode Command Line Tools.
#
# scripts/build-wx-macos.sh -> ~/.cache/wx-3.3.3-macos
#
# Dependency tracking is off: its bootstrap fails with several -arch flags.
# MACOSX_MIN (default 11.0) is the oldest macOS the app runs on, for both
# slices: the libc++ in current SDKs supports nothing older, and macOS 11 is
# also where Apple Silicon starts. Image/zlib/regex/expat libraries are
# wx's bundled copies, so the app links only against system frameworks.
# The repo's vendor tree stays pristine; the build lives in ~/.cache/wxbuild.
set -e
REPO=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
SRC="$REPO/thirdparty/wxwidgets/wxWidgets-3.3.3"
BUILD="$HOME/.cache/wxbuild/wxWidgets-3.3.3-macos"
PREFIX="${WX_MACOS_PREFIX:-$HOME/.cache/wx-3.3.3-macos}"
MACOSX_MIN="${MACOSX_MIN:-11.0}"
JOBS="${JOBS:-$(sysctl -n hw.ncpu)}"
[ -d "$SRC" ] || { echo "thirdparty wxWidgets tree missing: $SRC" >&2; exit 1; }
rm -rf "$BUILD"
mkdir -p "$HOME/.cache/wxbuild"
cp -R "$SRC" "$BUILD"
trap 'rm -rf "$BUILD"' 0
chmod +x "$BUILD/configure" "$BUILD/config.guess" "$BUILD/config.sub" "$BUILD/install-sh" 2>/dev/null || true
mkdir -p "$BUILD/build-macos"
cd "$BUILD/build-macos"
sh ../configure --prefix="$PREFIX" --with-osx_cocoa \
--disable-shared --enable-monolithic \
--enable-universal_binary=arm64,x86_64 \
--with-macosx-version-min="$MACOSX_MIN" \
--disable-dependency-tracking \
--with-libpng=builtin --with-libjpeg=builtin --without-libtiff \
--with-zlib=builtin --with-expat=builtin --with-regex=builtin \
--without-liblzma --without-libcurl \
--with-opengl=no --disable-stc --disable-webview --disable-mediactrl \
--disable-tests
make -j"$JOBS"
make install
lib=$(ls "$PREFIX"/lib/libwx_osx_cocoau-3.3*.a | head -1)
lipo -info "$lib"
echo "installed: $PREFIX ($lib)"
+140
View File
@@ -0,0 +1,140 @@
Subject: [PATCH 0009] macOS: wxOSX through wx-config, logical sizes, clang runtime
--- a/build.rs
+++ b/build.rs
@@ -42,12 +42,12 @@
target_os() == "linux"
}
-// alkane-toolkit patch: Linux (wxGTK) and Windows/GNU (wxMSW built with
-// mingw-w64, natively or cross from Linux) both build against a wx prefix
-// described by its wx-config script, so they share one code path. Upstream's
-// MSVC/nmake and macOS download-and-build paths are left as they were.
+// alkane-toolkit patch: Linux (wxGTK), macOS (wxOSX/Cocoa, universal static
+// build) and Windows/GNU (wxMSW built with mingw-w64, natively or cross from
+// Linux) all build against a wx prefix described by its wx-config script, so
+// they share one code path. Upstream's MSVC/nmake path is left as it was.
fn uses_wx_config() -> bool {
- is_linux() || (is_windows() && !is_msvc())
+ is_linux() || is_osx() || (is_windows() && !is_msvc())
}
fn is_stub() -> bool {
@@ -278,7 +278,14 @@
build.cpp(true)
.file("cpp_src/wxbridge.cpp")
.file("cpp_src/widgets_bridge.cpp");
- for f in cxxflags.split_whitespace() {
+ let mut flags = cxxflags.split_whitespace();
+ while let Some(f) = flags.next() {
+ // A universal wx prefix reports `-arch arm64 -arch x86_64`; cargo builds
+ // one target at a time and cc adds that target's own -arch.
+ if is_osx() && f == "-arch" {
+ flags.next();
+ continue;
+ }
build.flag(f);
}
if is_linux() {
@@ -308,7 +315,53 @@
}
build.compile("wxbridge");
- for flag in libs.split_whitespace() {
+ if is_osx() {
+ // wxOSX's Objective-C uses @available, which calls
+ // ___isPlatformVersionAtLeast from clang's compiler runtime. clang
+ // links that runtime itself, but rustc drives the link without it.
+ let resource_dir = Command::new("clang")
+ .arg("-print-resource-dir")
+ .output()
+ .ok()
+ .filter(|o| o.status.success())
+ .and_then(|o| String::from_utf8(o.stdout).ok())
+ .map(|s| s.trim().to_string())
+ .ok_or("wx-rs: cannot ask clang for its resource directory")?;
+ let rt = Path::new(&resource_dir).join("lib").join("darwin");
+ if !rt.join("libclang_rt.osx.a").exists() {
+ return Err(format!("wx-rs: no libclang_rt.osx.a in {}", rt.display()).into());
+ }
+ println!("cargo:rustc-link-search=native={}", rt.display());
+ println!("cargo:rustc-link-lib=static=clang_rt.osx");
+ }
+
+ let mut lib_flags = libs.split_whitespace();
+ while let Some(flag) = lib_flags.next() {
+ if is_osx() {
+ match flag {
+ "-arch" => {
+ lib_flags.next();
+ continue;
+ }
+ "-framework" => {
+ if let Some(name) = lib_flags.next() {
+ println!("cargo:rustc-link-lib=framework={}", name);
+ }
+ continue;
+ }
+ "-weak_framework" => {
+ if let Some(name) = lib_flags.next() {
+ println!("cargo:rustc-link-arg=-Wl,-weak_framework,{}", name);
+ }
+ continue;
+ }
+ _ if flag.starts_with("-Wl,") => {
+ println!("cargo:rustc-link-arg={}", flag);
+ continue;
+ }
+ _ => {}
+ }
+ }
if flag.ends_with(".a") && Path::new(flag).is_absolute() {
// static wx builds: wx-config emits the archive as a full path
let file = Path::new(flag).file_name().and_then(|f| f.to_str()).unwrap_or(flag);
--- a/cpp_src/wxbridge.cpp
+++ b/cpp_src/wxbridge.cpp
@@ -492,21 +492,12 @@
// The logical window size
Size get_client_size() {
-#ifdef __APPLE__
- int status_bar_height;
- if (wxGetApp().frame->GetStatusBar()) {
- status_bar_height = wxGetApp().frame->GetStatusBar()->GetRect().height;
- } else {
- status_bar_height = 0;
- }
- float scale_factor = wxGetApp().frame->GetDPIScaleFactor();
- wxSize s = wxGetApp().frame->GetClientSize();
- struct Size sz = {s.x * scale_factor, (s.y + status_bar_height) * scale_factor};
- return sz;
-#elif defined(__linux__)
- // alkane-toolkit patch: wxGTK3 path (upstream only knew Apple vs Windows)
+#if defined(__linux__) || defined(__APPLE__)
+ // alkane-toolkit patch: wxGTK3 and wxOSX both report logical (DIP) sizes,
+ // like every other bridge size. Upstream's Apple branch scaled to physical
+ // pixels through a float -> int narrowing current clang rejects.
wxSize s = wxGetApp().frame->GetClientSize();
- return Size {(unsigned int)s.x, (unsigned int)s.y};
+ return Size {s.x, s.y};
#else
HWND hwnd = (HWND) wxGetApp().frame->GetHandle();
RECT rect;
@@ -559,15 +550,10 @@
}
Size get_mouse_position(wxMouseEvent &event) {
-#ifdef __APPLE__
- wxPoint p = event.GetPosition();
- float scale_factor = wxGetApp().frame->GetDPIScaleFactor();
- struct Size s = {p.x * scale_factor, p.y * scale_factor};
- return s;
-#else
+ // alkane-toolkit patch: logical (DIP) coordinates on every platform,
+ // matching get_client_size (upstream scaled them on Apple).
wxPoint p = event.GetPosition();
return Size {p.x, p.y};
-#endif
}
int get_mouse_wheel_rotation(wxMouseEvent &event) {
+1
View File
@@ -27,6 +27,7 @@ later changes go in new patches.
| 0006 | Build: platform from the target, not the host; Windows/GNU via `wx-config` |
| 0007 | `wxbridge.cpp` on wxMSW: no input-swallowing overlay, appearance before the first window, work-area sizing, executable icon, UTF-8 menu fix |
| 0008 | Widget bridge on wxMSW: generic data-view input and tooltips, DIP boundary, anti-aliased shapes, themed selection colours |
| 0009 | macOS: wxOSX (universal static) through `wx-config`, logical sizes on Apple, clang compiler runtime for `@available` |
History: the round 19 health-tooltip fix (GTK tip area converted from
bin-window to widget coordinates) used to be a separate patch on top of an
+60 -7
View File
@@ -42,12 +42,12 @@ fn is_linux() -> bool {
target_os() == "linux"
}
// alkane-toolkit patch: Linux (wxGTK) and Windows/GNU (wxMSW built with
// mingw-w64, natively or cross from Linux) both build against a wx prefix
// described by its wx-config script, so they share one code path. Upstream's
// MSVC/nmake and macOS download-and-build paths are left as they were.
// alkane-toolkit patch: Linux (wxGTK), macOS (wxOSX/Cocoa, universal static
// build) and Windows/GNU (wxMSW built with mingw-w64, natively or cross from
// Linux) all build against a wx prefix described by its wx-config script, so
// they share one code path. Upstream's MSVC/nmake path is left as it was.
fn uses_wx_config() -> bool {
is_linux() || (is_windows() && !is_msvc())
is_linux() || is_osx() || (is_windows() && !is_msvc())
}
fn is_stub() -> bool {
@@ -278,7 +278,14 @@ fn build_with_wx_config() -> Result<(), Box<dyn Error>> {
build.cpp(true)
.file("cpp_src/wxbridge.cpp")
.file("cpp_src/widgets_bridge.cpp");
for f in cxxflags.split_whitespace() {
let mut flags = cxxflags.split_whitespace();
while let Some(f) = flags.next() {
// A universal wx prefix reports `-arch arm64 -arch x86_64`; cargo builds
// one target at a time and cc adds that target's own -arch.
if is_osx() && f == "-arch" {
flags.next();
continue;
}
build.flag(f);
}
if is_linux() {
@@ -308,7 +315,53 @@ fn build_with_wx_config() -> Result<(), Box<dyn Error>> {
}
build.compile("wxbridge");
for flag in libs.split_whitespace() {
if is_osx() {
// wxOSX's Objective-C uses @available, which calls
// ___isPlatformVersionAtLeast from clang's compiler runtime. clang
// links that runtime itself, but rustc drives the link without it.
let resource_dir = Command::new("clang")
.arg("-print-resource-dir")
.output()
.ok()
.filter(|o| o.status.success())
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_string())
.ok_or("wx-rs: cannot ask clang for its resource directory")?;
let rt = Path::new(&resource_dir).join("lib").join("darwin");
if !rt.join("libclang_rt.osx.a").exists() {
return Err(format!("wx-rs: no libclang_rt.osx.a in {}", rt.display()).into());
}
println!("cargo:rustc-link-search=native={}", rt.display());
println!("cargo:rustc-link-lib=static=clang_rt.osx");
}
let mut lib_flags = libs.split_whitespace();
while let Some(flag) = lib_flags.next() {
if is_osx() {
match flag {
"-arch" => {
lib_flags.next();
continue;
}
"-framework" => {
if let Some(name) = lib_flags.next() {
println!("cargo:rustc-link-lib=framework={}", name);
}
continue;
}
"-weak_framework" => {
if let Some(name) = lib_flags.next() {
println!("cargo:rustc-link-arg=-Wl,-weak_framework,{}", name);
}
continue;
}
_ if flag.starts_with("-Wl,") => {
println!("cargo:rustc-link-arg={}", flag);
continue;
}
_ => {}
}
}
if flag.ends_with(".a") && Path::new(flag).is_absolute() {
// static wx builds: wx-config emits the archive as a full path
let file = Path::new(flag).file_name().and_then(|f| f.to_str()).unwrap_or(flag);
+7 -21
View File
@@ -492,21 +492,12 @@ extern "C" {
// The logical window size
Size get_client_size() {
#ifdef __APPLE__
int status_bar_height;
if (wxGetApp().frame->GetStatusBar()) {
status_bar_height = wxGetApp().frame->GetStatusBar()->GetRect().height;
} else {
status_bar_height = 0;
}
float scale_factor = wxGetApp().frame->GetDPIScaleFactor();
wxSize s = wxGetApp().frame->GetClientSize();
struct Size sz = {s.x * scale_factor, (s.y + status_bar_height) * scale_factor};
return sz;
#elif defined(__linux__)
// alkane-toolkit patch: wxGTK3 path (upstream only knew Apple vs Windows)
#if defined(__linux__) || defined(__APPLE__)
// alkane-toolkit patch: wxGTK3 and wxOSX both report logical (DIP) sizes,
// like every other bridge size. Upstream's Apple branch scaled to physical
// pixels through a float -> int narrowing current clang rejects.
wxSize s = wxGetApp().frame->GetClientSize();
return Size {(unsigned int)s.x, (unsigned int)s.y};
return Size {s.x, s.y};
#else
HWND hwnd = (HWND) wxGetApp().frame->GetHandle();
RECT rect;
@@ -559,15 +550,10 @@ extern "C" {
}
Size get_mouse_position(wxMouseEvent &event) {
#ifdef __APPLE__
wxPoint p = event.GetPosition();
float scale_factor = wxGetApp().frame->GetDPIScaleFactor();
struct Size s = {p.x * scale_factor, p.y * scale_factor};
return s;
#else
// alkane-toolkit patch: logical (DIP) coordinates on every platform,
// matching get_client_size (upstream scaled them on Apple).
wxPoint p = event.GetPosition();
return Size {p.x, p.y};
#endif
}
int get_mouse_wheel_rotation(wxMouseEvent &event) {