Skip to content

Commit

Permalink
Merge pull request #7 from s-ludwig/osx_static_framework
Browse files Browse the repository at this point in the history
Add a "static" configuration that uses static linking on macOS
  • Loading branch information
FreeSlave authored Jul 18, 2024
2 parents 3c031c5 + 9f00524 commit b31da89
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,19 @@
"volumeinfo" : "~>0.2.2",
"inilike" : "~>1.2.0"
},

"configurations": [
{
"name": "static",
"versions": [
"TrashCanStatic"
],
"lflags-osx": [
"-framework", "CoreServices"
]
},
{
"name": "dynamic",
}
]
}
36 changes: 21 additions & 15 deletions source/trashcan.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;}
}
}

/**
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b31da89

Please sign in to comment.