mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
Installer: libmlg_drm and libdrm_mlg ship with the driver in /usr/local/lib
The Linux-file client libraries speak the driver's RPC, so they must match the installed driver; folders that bundle their own copies (RADV for llama.cpp, mlg-run) broke whenever the driver's transport changed. The app now carries them in Contents/Resources/Runtime with the HSA runtime and installs them to /usr/local/lib with the same staging, signature and team checks and rollback; activate.sh --install-hsa builds and installs them too, and the disk image checks them. RADV's install gets /usr/local/lib as a second rpath after @loader_path, so a tree without its own copy loads the driver's.
This commit is contained in:
1 parent
ec8198541d
commit
3e4651d739
4 files changed
+35
-15
No files matched your search
@@ -49,10 +49,12 @@ private let firmwareRootPath = "/Library/Application Support/MacLinuxGPU/firmwar
|
||||
// The disk image contains the signed host app and its embedded dext. Verify the
|
||||
// exact package before allowing a privileged replacement in /Applications.
|
||||
private enum InstallPackage {
|
||||
// Only the HSA runtime ships with the driver; it must match the dext.
|
||||
// HRX and Loom belong to the applications that use them (LemonSeed
|
||||
// bundles its own).
|
||||
private static let runtimeFiles = ["libhsa-runtime64.0.1.0.dylib"]
|
||||
// The HSA runtime and the Linux-file client libraries (libmlg_drm and
|
||||
// the libdrm over it that RADV links) ship with the driver; each must
|
||||
// match the dext, whose RPC they speak. HRX and Loom belong to the
|
||||
// applications that use them (LemonSeed bundles its own).
|
||||
private static let runtimeFiles = ["libhsa-runtime64.0.1.0.dylib",
|
||||
"libmlg_drm.dylib", "libdrm_mlg.dylib"]
|
||||
private static let runtimeLinks = [
|
||||
"libhsa-runtime64.1.dylib": "libhsa-runtime64.0.1.0.dylib",
|
||||
"libhsa-runtime64.dylib": "libhsa-runtime64.1.dylib"
|
||||
@@ -172,6 +174,7 @@ private enum InstallPackage {
|
||||
local_stage=\(shellQuote(localStage))
|
||||
local_backup=\(shellQuote(localBackup))
|
||||
local_dst=/usr/local/lib
|
||||
local_names="libhsa-runtime64.0.1.0.dylib libhsa-runtime64.1.dylib libhsa-runtime64.dylib libmlg_drm.dylib libdrm_mlg.dylib"
|
||||
fw_root=\(shellQuote(firmwareRootPath))
|
||||
fw_stage=\(shellQuote(firmwareStage))
|
||||
fw_backup=\(shellQuote(firmwareBackup))
|
||||
@@ -190,7 +193,7 @@ private enum InstallPackage {
|
||||
if [ "$committed" -ne 1 ]; then
|
||||
set +e
|
||||
if [ "$local_started" -eq 1 ]; then
|
||||
for name in libhsa-runtime64.0.1.0.dylib libhsa-runtime64.1.dylib libhsa-runtime64.dylib; do
|
||||
for name in $local_names; do
|
||||
if [ ! -e "$local_stage/$name" ] && [ ! -L "$local_stage/$name" ]; then
|
||||
/bin/rm -f "$local_dst/$name" || result=1
|
||||
fi
|
||||
@@ -238,10 +241,11 @@ private enum InstallPackage {
|
||||
if [ ! -e "$entry" ] && [ ! -L "$entry" ]; then continue; fi
|
||||
case "${entry##*/}" in
|
||||
libhsa-runtime64.0.1.0.dylib|libhsa-runtime64.1.dylib|libhsa-runtime64.dylib) ;;
|
||||
libmlg_drm.dylib|libdrm_mlg.dylib) ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
done
|
||||
for lib in libhsa-runtime64.0.1.0.dylib; do
|
||||
for lib in libhsa-runtime64.0.1.0.dylib libmlg_drm.dylib libdrm_mlg.dylib; do
|
||||
[ -f "$runtime_stage/$lib" ] && [ ! -L "$runtime_stage/$lib" ]
|
||||
/usr/bin/codesign --verify --strict "$runtime_stage/$lib"
|
||||
/usr/bin/codesign -dv "$runtime_stage/$lib" 2>&1 | /usr/bin/grep -Fxq \(shellQuote("TeamIdentifier=" + expectedTeamIdentifier))
|
||||
@@ -252,6 +256,8 @@ private enum InstallPackage {
|
||||
/usr/bin/ditto "$runtime_stage/libhsa-runtime64.0.1.0.dylib" "$local_stage/libhsa-runtime64.0.1.0.dylib"
|
||||
/bin/ln -s libhsa-runtime64.0.1.0.dylib "$local_stage/libhsa-runtime64.1.dylib"
|
||||
/bin/ln -s libhsa-runtime64.1.dylib "$local_stage/libhsa-runtime64.dylib"
|
||||
/usr/bin/ditto "$runtime_stage/libmlg_drm.dylib" "$local_stage/libmlg_drm.dylib"
|
||||
/usr/bin/ditto "$runtime_stage/libdrm_mlg.dylib" "$local_stage/libdrm_mlg.dylib"
|
||||
if [ -e "$runtime_dst" ]; then /bin/mv "$runtime_dst" "$runtime_backup"; runtime_old=1; fi
|
||||
/bin/mv "$runtime_stage" "$runtime_dst"
|
||||
runtime_new=1
|
||||
@@ -259,7 +265,7 @@ private enum InstallPackage {
|
||||
/bin/mv "$stage" "$dst"
|
||||
app_new=1
|
||||
local_started=1
|
||||
for name in libhsa-runtime64.0.1.0.dylib libhsa-runtime64.1.dylib libhsa-runtime64.dylib; do
|
||||
for name in $local_names; do
|
||||
if [ -e "$local_dst/$name" ] || [ -L "$local_dst/$name" ]; then
|
||||
/bin/mv "$local_dst/$name" "$local_backup/$name"
|
||||
fi
|
||||
@@ -279,7 +285,7 @@ private enum InstallPackage {
|
||||
fi
|
||||
committed=1
|
||||
if [ "$fw_old" -eq 1 ]; then /bin/rm -rf "$fw_backup"; fi
|
||||
printf 'Installed %s\\nPrevious app backup: %s\\nPrevious runtime backup: %s\\nPrevious /usr/local HSA backup: %s\\n' "$dst" "$backup" "$runtime_backup" "$local_backup"
|
||||
printf 'Installed %s\\nPrevious app backup: %s\\nPrevious runtime backup: %s\\nPrevious /usr/local runtime backup: %s\\n' "$dst" "$backup" "$runtime_backup" "$local_backup"
|
||||
"""
|
||||
// AppleScript handles the administrator prompt. The command is fixed;
|
||||
// only paths, each shell quoted, vary. A failure retains the old app.
|
||||
|
||||
+13
-4
@@ -157,9 +157,11 @@ fi
|
||||
# 2. Build the HSA runtime dylib (if --install-hsa).
|
||||
# ---------------------------------------------------------------------------
|
||||
if [[ $install_hsa -eq 1 ]]; then
|
||||
echo "==> building HSA runtime dylib (make hsa)"
|
||||
make -C "$PROJECT_ROOT" hsa
|
||||
for source in "$PROJECT_ROOT/build/hsa/libhsa-runtime64.0.1.0.dylib"; do
|
||||
echo "==> building HSA runtime dylib (make hsa) and the Linux-file client libraries"
|
||||
make -C "$PROJECT_ROOT" hsa libdrm-mlg
|
||||
for source in "$PROJECT_ROOT/build/hsa/libhsa-runtime64.0.1.0.dylib" \
|
||||
"$PROJECT_ROOT/build/libdrm-mlg/lib/libmlg_drm.dylib" \
|
||||
"$PROJECT_ROOT/build/libdrm-mlg/lib/libdrm_mlg.dylib"; do
|
||||
[[ -f "$source" ]] || {
|
||||
echo "error: missing HSA runtime: $source" >&2
|
||||
exit 1
|
||||
@@ -329,7 +331,9 @@ stage_runtime_payload() {
|
||||
}
|
||||
rm -rf "$payload"
|
||||
mkdir -p "$payload"
|
||||
for source in "$PROJECT_ROOT/build/hsa/libhsa-runtime64.0.1.0.dylib"; do
|
||||
for source in "$PROJECT_ROOT/build/hsa/libhsa-runtime64.0.1.0.dylib" \
|
||||
"$PROJECT_ROOT/build/libdrm-mlg/lib/libmlg_drm.dylib" \
|
||||
"$PROJECT_ROOT/build/libdrm-mlg/lib/libdrm_mlg.dylib"; do
|
||||
[[ -f "$source" && ! -L "$source" ]] || {
|
||||
echo "error: expected a regular runtime library: $source" >&2
|
||||
return 1
|
||||
@@ -531,6 +535,11 @@ if [[ $install_hsa -eq 1 ]]; then
|
||||
/usr/local/lib/libhsa-runtime64.0.1.0.dylib
|
||||
sudo ln -sfn libhsa-runtime64.0.1.0.dylib /usr/local/lib/libhsa-runtime64.1.dylib
|
||||
sudo ln -sfn libhsa-runtime64.1.dylib /usr/local/lib/libhsa-runtime64.dylib
|
||||
# The Linux-file client libraries RADV and llama.cpp's Vulkan backend load
|
||||
# (by @rpath, which their folders point at /usr/local/lib).
|
||||
echo "==> installing libmlg_drm.dylib and libdrm_mlg.dylib to /usr/local/lib/"
|
||||
sudo cp -f "$PROJECT_ROOT/build/libdrm-mlg/lib/libmlg_drm.dylib" \
|
||||
"$PROJECT_ROOT/build/libdrm-mlg/lib/libdrm_mlg.dylib" /usr/local/lib/
|
||||
|
||||
# Copy the public header.
|
||||
echo "==> copying mac_hsa.h to /usr/local/include/"
|
||||
|
||||
@@ -150,10 +150,11 @@ validate_runtime_payload() {
|
||||
[[ -e "$entry" || -L "$entry" ]] || continue
|
||||
case "${entry##*/}" in
|
||||
libhsa-runtime64.0.1.0.dylib|libhsa-runtime64.1.dylib|libhsa-runtime64.dylib) ;;
|
||||
libmlg_drm.dylib|libdrm_mlg.dylib) ;;
|
||||
*) echo "error: unexpected runtime payload entry: $entry" >&2; return 1 ;;
|
||||
esac
|
||||
done
|
||||
for name in libhsa-runtime64.0.1.0.dylib; do
|
||||
for name in libhsa-runtime64.0.1.0.dylib libmlg_drm.dylib libdrm_mlg.dylib; do
|
||||
[[ -f "$runtime/$name" && ! -L "$runtime/$name" ]] || {
|
||||
echo "error: required runtime library is missing or linked: $name" >&2
|
||||
return 1
|
||||
@@ -194,7 +195,8 @@ cat > "$stage_path/Install MacLinuxGPU.txt" <<'EOF'
|
||||
Double-click MacLinuxGPUHost.app to install and activate the driver.
|
||||
Follow the app's instructions for macOS approval.
|
||||
Keep the app in /Applications after installation so macOS can manage updates.
|
||||
The app also installs the bundled HSA runtime library and the bundled AMD GPU
|
||||
The app also installs the bundled HSA runtime library and the Linux-file
|
||||
client libraries (libmlg_drm, libdrm_mlg) to /usr/local/lib, and the bundled AMD GPU
|
||||
firmware (linux-firmware, see its WHENCE file) to
|
||||
/Library/Application Support/MacLinuxGPU/firmware.
|
||||
EOF
|
||||
|
||||
@@ -97,12 +97,15 @@ step "Installing into build/radv/install"
|
||||
mkdir -p "$PREFIX/lib" "$PREFIX/share/vulkan/icd.d"
|
||||
install -m 755 "$BUILD/src/amd/vulkan/libvulkan_radeon.dylib" "$PREFIX/lib/"
|
||||
install -m 755 "$LIBDRM/lib/libdrm_mlg.dylib" "$LIBDRM/lib/libmlg_drm.dylib" "$PREFIX/lib/"
|
||||
# The driver finds libdrm-mlg next to itself, wherever the tree is moved.
|
||||
# The driver finds libdrm-mlg next to itself, wherever the tree is moved, or
|
||||
# else where the MacLinuxGPU installer puts it (/usr/local/lib), which is how
|
||||
# a folder that does not carry its own copy (LlamaAMDVulkanOnMac) runs.
|
||||
lib="$PREFIX/lib/libvulkan_radeon.dylib"
|
||||
while read -r rpath; do
|
||||
install_name_tool -delete_rpath "$rpath" "$lib" 2>/dev/null || true
|
||||
done < <(otool -l "$lib" | awk '/LC_RPATH/ { getline; getline; print $2 }')
|
||||
install_name_tool -add_rpath @loader_path "$lib" 2>/dev/null
|
||||
install_name_tool -add_rpath /usr/local/lib "$lib" 2>/dev/null
|
||||
for dylib in "$lib" "$PREFIX/lib/libdrm_mlg.dylib" "$PREFIX/lib/libmlg_drm.dylib"; do
|
||||
codesign --force --sign - "$dylib" 2>/dev/null
|
||||
done
|
||||
|
||||
Reference in new issue
Block a user