#!/usr/bin/env bash # Build the native Emacs FFI module and place it beside the Lisp package. set -euo pipefail # Resolve checkout and native host independently of Cargo's default target. project_root="$(cd "$(dirname "$0")/.." && pwd)" native_target="$(rustc -vV | awk '$1 == "host:" { print $2 }')" if [[ -z "${native_target}" ]]; then printf '%s\n' 'Could not determine the Rust host target.' >&2 exit 1 fi # The produced library follows the module suffix of supported Unix Emacs builds. case "$(uname -s)" in Darwin) native_suffix='dylib' ;; Linux) native_suffix='so' ;; *) printf '%s\n' 'This helper supports macOS and Linux native module builds.' >&2; exit 1 ;; esac # Keep build products separate from source and explicit in cross-target setups. cargo build --manifest-path "${project_root}/Cargo.toml" \ --release --locked --package lispm-llm-emacs \ --target "${native_target}" --target-dir "${project_root}/target" native_library="${project_root}/target/${native_target}/release/liblispm_llm_emacs.${native_suffix}" native_destination="${project_root}/emacs/lispm-llm-native.${native_suffix}" # Replace the inode atomically so an already loaded module is not truncated. native_staged="$(mktemp "${native_destination}.XXXXXX")" trap 'rm -f "${native_staged}"' EXIT cp "${native_library}" "${native_staged}" mv -f "${native_staged}" "${native_destination}" printf 'Emacs module: %s\n' "${native_destination}"