From 84a7c39718392b208b7d028133a61e8e0c0899c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 18 Jul 2024 09:45:33 +0200 Subject: [PATCH 1/2] Add a "static" configuration that uses static linking on macOS. The dlopen() call fails on the latest macOS versions: dlopen(CoreServices.framework/Versions/A/CoreServices, 0x0002): tried: 'CoreServices.framework/Versions/A/CoreServices' (no such file), '/System/Volumes/Preboot/Cryptexes/OSCoreServices.framework/Versions/A/CoreServices' (no such file), '/usr/lib/CoreServices.framework/Versions/A/CoreServices' (no such file, not in dyldcache), 'CoreServices.framework/Versions/A/CoreServices' (no such file) Using the "-framework CoreServices" linker flag statically links agains the CoreServices framework instead, which should be the best approach for most applications. --- dub.json | 15 +++++++++++++++ source/trashcan.d | 36 +++++++++++++++++++++--------------- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/dub.json b/dub.json index a1f303a..0325043 100644 --- a/dub.json +++ b/dub.json @@ -13,4 +13,19 @@ "volumeinfo" : "~>0.2.2", "inilike" : "~>1.2.0" }, + + "configurations": [ + { + "name": "static", + "versions": [ + "TrashCanStatic" + ], + "lflags-osx": [ + "-framework", "CoreServices" + ] + }, + { + "name": "dynamic", + } + ] } diff --git a/source/trashcan.d b/source/trashcan.d index f2b1b4d..06b9619 100644 --- a/source/trashcan.d +++ b/source/trashcan.d @@ -182,8 +182,13 @@ private: alias int OSStatus; alias uint OptionBits; - extern(C) @nogc @system OSStatus _dummy_FSPathMakeRefWithOptions(const(char)* path, OptionBits, FSRef*, Boolean*) nothrow {return 0;} - extern(C) @nogc @system OSStatus _dummy_FSMoveObjectToTrashSync(const(FSRef)*, FSRef*, OptionBits) nothrow {return 0;} + version (TrashCanStatic) { + extern(C) @nogc @system OSStatus FSPathMakeRefWithOptions(const(char)* path, OptionBits, FSRef*, Boolean*) nothrow; + extern(C) @nogc @system OSStatus FSMoveObjectToTrashSync(const(FSRef)*, FSRef*, OptionBits) nothrow; + } else { + extern(C) @nogc @system OSStatus _dummy_FSPathMakeRefWithOptions(const(char)* path, OptionBits, FSRef*, Boolean*) nothrow {return 0;} + extern(C) @nogc @system OSStatus _dummy_FSMoveObjectToTrashSync(const(FSRef)*, FSRef*, OptionBits) nothrow {return 0;} + } } /** @@ -222,27 +227,28 @@ private: throw new Exception(format("SHFileOperation failed with error code %d", r)); } } else version(OSX) { - void* handle = dlopen("CoreServices.framework/Versions/A/CoreServices", RTLD_NOW | RTLD_LOCAL); - if (handle !is null) { + version (TrashCanStatic) {} + else { + void* handle = dlopen("CoreServices.framework/Versions/A/CoreServices", RTLD_NOW | RTLD_LOCAL); + if (handle is null) + throw new Exception(fromStringz(dlerror()).idup); scope(exit) dlclose(handle); - auto ptrFSPathMakeRefWithOptions = cast(typeof(&_dummy_FSPathMakeRefWithOptions))dlsym(handle, "FSPathMakeRefWithOptions"); - if (ptrFSPathMakeRefWithOptions is null) { + auto FSPathMakeRefWithOptions = cast(typeof(&_dummy_FSPathMakeRefWithOptions))dlsym(handle, "FSPathMakeRefWithOptions"); + if (FSPathMakeRefWithOptions is null) { throw new Exception(fromStringz(dlerror()).idup); } - auto ptrFSMoveObjectToTrashSync = cast(typeof(&_dummy_FSMoveObjectToTrashSync))dlsym(handle, "FSMoveObjectToTrashSync"); - if (ptrFSMoveObjectToTrashSync is null) { + auto FSMoveObjectToTrashSync = cast(typeof(&_dummy_FSMoveObjectToTrashSync))dlsym(handle, "FSMoveObjectToTrashSync"); + if (FSMoveObjectToTrashSync is null) { throw new Exception(fromStringz(dlerror()).idup); } - - FSRef source; - enforce(ptrFSPathMakeRefWithOptions(toStringz(path), 1, &source, null) == 0, "Could not make FSRef from path"); - FSRef target; - enforce(ptrFSMoveObjectToTrashSync(&source, &target, 0) == 0, "Could not move path to trash"); - } else { - throw new Exception(fromStringz(dlerror()).idup); } + + FSRef source; + enforce(FSPathMakeRefWithOptions(toStringz(path), 1, &source, null) == 0, "Could not make FSRef from path"); + FSRef target; + enforce(FSMoveObjectToTrashSync(&source, &target, 0) == 0, "Could not move path to trash"); } else { static if (isFreedesktop) { string dataPath = xdgDataHome(null, true); From 9f005242b37863a8602e8800f6ac6ea5dea6f29a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 18 Jul 2024 09:48:10 +0200 Subject: [PATCH 2/2] Run on macos-13 instead of macos-latest to avoid ARM related D setup failure. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e48d42..ff503e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-latest, windows-latest, macos-13] dc: - ldc-latest - dmd-latest