diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d8c01b8..89a8ee6 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -57,6 +57,8 @@ jobs:
- run: cargo clippy --workspace --all-targets --locked -- -D warnings
- run: cargo test --workspace --locked
- run: cargo build --workspace --release --locked
+ # The screen reader library as it's packaged: its own size-first profile.
+ - run: cargo build --profile release-a11y --locked -p alias-calc-a11y
# aliasOS also runs on Apple Silicon: c_char is u8 there, so FFI
# mistakes only show on aarch64. A type check needs no cross linker.
- name: Type-check for aarch64
@@ -69,10 +71,25 @@ jobs:
# ignored in the debug test run.
- name: Performance budgets
run: cargo test --release --locked -- --ignored budget_ --test-threads=1
- - name: Benchmark scripts parse
+ - name: Scripts parse
run: |
python3 -m py_compile bench/calcbench.py
bash -n bench/run
+ sh -n install.sh
+ # A staged install and uninstall of the release build, as the
+ # PKGBUILD does it, and the installed desktop entry checked.
+ - name: Install and uninstall
+ run: |
+ apt-get install -y -qq --no-install-recommends desktop-file-utils >/dev/null
+ stage=$(mktemp -d)
+ PREFIX=/usr DESTDIR="$stage" BIN=target/release/alias-calc \
+ LIB=target/release-a11y/libalias_calc_a11y.so ./install.sh
+ desktop-file-validate "$stage/usr/share/applications/com.aliasproject.calc.desktop"
+ test "$(find "$stage" -type f | wc -l)" -eq 6
+ grep -qx 'Exec="/usr/bin/alias-calc"' "$stage/usr/share/applications/com.aliasproject.calc.desktop"
+ PREFIX=/usr DESTDIR="$stage" ./install.sh uninstall
+ test "$(find "$stage" -type f | wc -l)" -eq 0
+ rm -rf "$stage"
- name: Hand the workspace back to the runner user
if: always()
run: chown -R 1001:1001 "$GITHUB_WORKSPACE" "$RUNNER_TEMP"
diff --git a/Cargo.toml b/Cargo.toml
index cbda174..24c3fae 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -26,3 +26,10 @@ strip = true
[profile.dev.package."*"]
opt-level = 2
+
+# The screen reader library (a11y/) is packaged from this profile: it's loaded
+# only while Orca runs, so size matters more than speed there. "z" takes it
+# from 2.7 to 1.9 MB. The binary keeps `release`.
+[profile.release-a11y]
+inherits = "release"
+opt-level = "z"
diff --git a/README.md b/README.md
index 0b3ad93..4351c23 100644
--- a/README.md
+++ b/README.md
@@ -25,7 +25,16 @@ cargo build --workspace --release
The binary is `target/release/alias-calc`. The aim is to link nothing beyond libc and `libxkbcommon` (for keyboard layouts), with a pure-Rust Wayland client.
-Screen reader support is a separate library, `target/release/libalias_calc_a11y.so` (the `a11y/` crate, with AccessKit). The calculator loads it only when Orca is running, from beside its binary or from `/usr/lib/alias-calc/`, so without a screen reader it costs nothing. A package installs it to `/usr/lib/alias-calc/`.
+Screen reader support is a separate library, `target/release/libalias_calc_a11y.so` (the `a11y/` crate, with AccessKit). The calculator loads it only when Orca is running, from beside its binary, from `lib/alias-calc/` beside the binary's `bin/` (where `install.sh` puts it), or from `/usr/lib/alias-calc/`, so without a screen reader it costs nothing. A package installs it to `/usr/lib/alias-calc/`, built with its own size-first profile (`cargo build --profile release-a11y -p alias-calc-a11y`, into `target/release-a11y/`): 1.9 MB instead of 2.7 MB.
+
+## Install
+
+```sh
+./install.sh # build, then install into ~/.local
+./install.sh uninstall
+```
+
+It installs `bin/alias-calc`, the screen reader library in `lib/alias-calc/`, the desktop entry (`packaging/com.aliasproject.calc.desktop`, "Calculator" in the launcher) and the icons (`packaging/icons`). aliasOS packages it from the `alias-calc` PKGBUILD in aliasos-pkgs, which builds both first and then runs `PREFIX=/usr DESTDIR="$pkgdir" BIN=target/release/alias-calc LIB=target/release-a11y/libalias_calc_a11y.so ./install.sh`: with `BIN` and `LIB` set, nothing is built.
## Benchmark
diff --git a/install.sh b/install.sh
new file mode 100755
index 0000000..57b2246
--- /dev/null
+++ b/install.sh
@@ -0,0 +1,153 @@
+#!/bin/sh
+# Installs Alias Calc from this checkout: the release binary, the screen
+# reader library (loaded only while Orca runs), the desktop entry and the
+# icons.
+#
+# ./install.sh build, then install into ~/.local
+# ./install.sh uninstall remove what install put there
+#
+# PREFIX=/usr DESTDIR=pkg ./install.sh (packaging: aliasos-pkgs' PKGBUILD)
+# BIN=path/to/alias-calc LIB=path/to/libalias_calc_a11y.so ./install.sh
+# (install those, no build)
+#
+# PREFIX defaults to ~/.local; DESTDIR, if set, is put in front of every
+# path (for staging), and then no caches are refreshed. The library goes in
+# PREFIX/lib/alias-calc, one of the places src/a11y.rs looks for it.
+set -eu
+
+here=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
+prefix=${PREFIX:-$HOME/.local}
+destdir=${DESTDIR:-}
+app=com.aliasproject.calc
+library=libalias_calc_a11y.so
+
+# The prefix goes into the desktop entry's Exec line, quoted, and must
+# start the app from any directory: refuse a relative one, and characters
+# that line (or sed) would read as something else.
+case $prefix in
+/*) ;;
+*)
+ printf 'install.sh: PREFIX must be an absolute path: %s\n' "$prefix" >&2
+ exit 1
+ ;;
+esac
+case $prefix in
+*[\"\`\$\\%\&\|]* | *[[:cntrl:]]*)
+ printf 'install.sh: PREFIX can'"'"'t hold any of " ` $ \\ %% & | or a control character: %s\n' "$prefix" >&2
+ exit 1
+ ;;
+esac
+
+bindir=$destdir$prefix/bin
+libdir=$destdir$prefix/lib/alias-calc
+appdir=$destdir$prefix/share/applications
+icondir=$destdir$prefix/share/icons/hicolor
+
+say() { printf '%s\n' "$*"; }
+
+# Launchers read these caches; a user's ~/.local may have none. The icon
+# cache is only refreshed if there is one already: a cache made here would
+# hide icons that later installs add without refreshing it.
+refresh() {
+ [ -z "$destdir" ] || return 0
+ if command -v update-desktop-database >/dev/null 2>&1; then
+ update-desktop-database -q "$appdir" || true
+ fi
+ if [ -f "$icondir/icon-theme.cache" ] && command -v gtk-update-icon-cache >/dev/null 2>&1; then
+ gtk-update-icon-cache -q -f -t "$icondir" || true
+ fi
+}
+
+# Copies $1 to $2 through a temporary name in the same folder, then renames
+# it: a running alias-calc keeps the files it has open, and nothing ever
+# sees half a file.
+put() {
+ mkdir -p "$(dirname "$2")"
+ tmp=$(mktemp "$(dirname "$2")/.alias-calc.tmp.XXXXXX")
+ trap 'rm -f "$tmp"' EXIT
+ trap 'exit 130' INT TERM HUP
+ if ! { cp "$1" "$tmp" && chmod "$3" "$tmp" && mv -f "$tmp" "$2"; }; then
+ say "install.sh: couldn't put $2" >&2
+ exit 1
+ fi
+ trap - EXIT INT TERM HUP
+}
+
+uninstall() {
+ rm -f "$bindir/alias-calc" "$libdir/$library" "$appdir/$app.desktop" \
+ "$icondir/scalable/apps/$app.svg" "$icondir/16x16/apps/$app.svg" \
+ "$icondir/24x24/apps/$app.svg"
+ rmdir "$libdir" 2>/dev/null || true
+ # And any temporary file an install that was killed left.
+ for left in "$bindir"/.alias-calc.tmp.?????? "$libdir"/.alias-calc.tmp.?????? \
+ "$appdir"/.alias-calc.tmp.?????? "$icondir"/*/apps/.alias-calc.tmp.??????; do
+ if [ -f "$left" ]; then rm -f "$left"; fi
+ done
+ refresh
+ say "Removed Alias Calc from $destdir$prefix."
+}
+
+install_() {
+ bin=${BIN:-}
+ lib=${LIB:-}
+ # Both or neither: a build would replace a LIB given on its own.
+ if [ -n "$lib" ] && [ -z "$bin" ]; then
+ say "install.sh: set BIN with LIB (or neither, to build both)" >&2
+ exit 1
+ fi
+ if [ -z "$bin" ]; then
+ command -v cargo >/dev/null 2>&1 || {
+ say "install.sh: cargo is needed to build (or set BIN and LIB to built files)" >&2
+ exit 1
+ }
+ say "Building the release binary and the screen reader library..."
+ # The paths cargo reports for what it built, wherever its target
+ # dir puts them. (Kept, then read: a failed build stops here.) The
+ # library has its own size-first profile (release-a11y, Cargo.toml).
+ built=$(cd "$here" && cargo build --release --locked -p alias-calc \
+ --message-format=json-render-diagnostics &&
+ cargo build --profile release-a11y --locked -p alias-calc-a11y \
+ --message-format=json-render-diagnostics)
+ bin=$(printf '%s\n' "$built" | sed -n 's/.*"executable":"\([^"]*alias-calc\)".*/\1/p' | tail -n 1)
+ lib=$(printf '%s\n' "$built" | grep -o "\"[^\"]*/$library\"" | tr -d '"' | tail -n 1)
+ [ -n "$bin" ] || { say "install.sh: cargo didn't report a built alias-calc" >&2; exit 1; }
+ fi
+ [ -x "$bin" ] || { say "install.sh: no binary at $bin" >&2; exit 1; }
+ [ -n "$lib" ] && [ -f "$lib" ] || { say "install.sh: no $library (set LIB)" >&2; exit 1; }
+
+ put "$bin" "$bindir/alias-calc" 755
+ put "$lib" "$libdir/$library" 755
+
+ # The full path (quoted, for a PREFIX with spaces), so launchers find it
+ # whether or not PREFIX/bin is on their PATH. Written beside the source
+ # first, then put in place like the rest.
+ # (Named like put()'s temporary files, so an interrupted install leaves
+ # nothing that uninstall won't remove.)
+ mkdir -p "$appdir"
+ entry=$(mktemp "$appdir/.alias-calc.tmp.XXXXXX")
+ sed "s|^Exec=alias-calc\$|Exec=\"$prefix/bin/alias-calc\"|" \
+ "$here/packaging/$app.desktop" >"$entry"
+ put "$entry" "$appdir/$app.desktop" 644
+ rm -f "$entry"
+
+ # The mark at any size, and the pixel-grid files where it's drawn small.
+ for target in scalable:$app.svg 16x16:$app-16.svg 24x24:$app-24.svg; do
+ put "$here/packaging/icons/${target#*:}" "$icondir/${target%%:*}/apps/$app.svg" 644
+ done
+
+ refresh
+ say "Installed Alias Calc in $destdir$prefix:"
+ say " $bindir/alias-calc"
+ say " $libdir/$library (screen readers)"
+ say " $appdir/$app.desktop (\"Calculator\" in the launcher)"
+ say " $icondir/{scalable,16x16,24x24}/apps/$app.svg"
+}
+
+case "${1:-install}" in
+install) install_ ;;
+uninstall) uninstall ;;
+*)
+ say "usage: ./install.sh [install|uninstall]" >&2
+ exit 2
+ ;;
+esac
diff --git a/packaging/com.aliasproject.calc.desktop b/packaging/com.aliasproject.calc.desktop
new file mode 100644
index 0000000..b180057
--- /dev/null
+++ b/packaging/com.aliasproject.calc.desktop
@@ -0,0 +1,12 @@
+[Desktop Entry]
+Type=Application
+Name=Calculator
+GenericName=Calculator
+Comment=A tiny, instant calculator
+Exec=alias-calc
+Icon=com.aliasproject.calc
+Terminal=false
+Categories=Utility;Calculator;
+Keywords=alias-calc;calc;math;arithmetic;Alias Calc;
+StartupNotify=false
+StartupWMClass=com.aliasproject.calc
diff --git a/packaging/icons/com.aliasproject.calc-16.svg b/packaging/icons/com.aliasproject.calc-16.svg
new file mode 100644
index 0000000..e676946
--- /dev/null
+++ b/packaging/icons/com.aliasproject.calc-16.svg
@@ -0,0 +1,2 @@
+
+
diff --git a/packaging/icons/com.aliasproject.calc-24.svg b/packaging/icons/com.aliasproject.calc-24.svg
new file mode 100644
index 0000000..b38e6c5
--- /dev/null
+++ b/packaging/icons/com.aliasproject.calc-24.svg
@@ -0,0 +1,2 @@
+
+
diff --git a/packaging/icons/com.aliasproject.calc.svg b/packaging/icons/com.aliasproject.calc.svg
new file mode 100644
index 0000000..dd35693
--- /dev/null
+++ b/packaging/icons/com.aliasproject.calc.svg
@@ -0,0 +1,4 @@
+
+
diff --git a/src/a11y.rs b/src/a11y.rs
index 98f75a5..e8249e8 100644
--- a/src/a11y.rs
+++ b/src/a11y.rs
@@ -131,16 +131,26 @@ unsafe extern "C" {
fn dlerror() -> *const c_char;
}
-/// Where the library may be: beside the binary (a build tree, or a package
-/// that keeps them together), then where the package installs it.
+/// Where the library may be, in order: beside the binary (a build tree),
+/// in `lib/alias-calc` beside the binary's `bin` (install.sh: `/usr` for the
+/// package, `~/.local` for a user install), then the package's path.
fn library_paths() -> Vec {
+ let exe = std::env::current_exe().ok();
+ candidates(exe.as_deref())
+}
+
+fn candidates(exe: Option<&std::path::Path>) -> Vec {
let mut paths = Vec::new();
- if let Ok(exe) = std::env::current_exe()
- && let Some(dir) = exe.parent()
- {
+ if let Some(dir) = exe.and_then(|e| e.parent()) {
paths.push(dir.join(LIBRARY));
+ if let Some(prefix) = dir.parent() {
+ paths.push(prefix.join("lib/alias-calc").join(LIBRARY));
+ }
+ }
+ let package = PathBuf::from("/usr/lib/alias-calc").join(LIBRARY);
+ if !paths.contains(&package) {
+ paths.push(package);
}
- paths.push(PathBuf::from("/usr/lib/alias-calc").join(LIBRARY));
paths
}
@@ -472,7 +482,19 @@ mod tests {
}
#[test]
- fn looks_beside_the_binary_first() {
+ fn looks_beside_the_binary_then_under_its_prefix() {
+ let home = candidates(Some(std::path::Path::new("/home/m/.local/bin/alias-calc")));
+ assert_eq!(
+ home,
+ [
+ PathBuf::from("/home/m/.local/bin").join(LIBRARY),
+ PathBuf::from("/home/m/.local/lib/alias-calc").join(LIBRARY),
+ PathBuf::from("/usr/lib/alias-calc").join(LIBRARY),
+ ]
+ );
+ // The package's own path isn't listed twice.
+ let package = candidates(Some(std::path::Path::new("/usr/bin/alias-calc")));
+ assert_eq!(package.len(), 2);
let paths = library_paths();
assert_eq!(
paths.last().unwrap(),