Skip to content

Commit b31da89

Browse files
authored
Merge pull request #7 from s-ludwig/osx_static_framework
Add a "static" configuration that uses static linking on macOS
2 parents 3c031c5 + 9f00524 commit b31da89

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
os: [ubuntu-latest, windows-latest, macos-latest]
16+
os: [ubuntu-latest, windows-latest, macos-13]
1717
dc:
1818
- ldc-latest
1919
- dmd-latest

dub.json

+15
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,19 @@
1313
"volumeinfo" : "~>0.2.2",
1414
"inilike" : "~>1.2.0"
1515
},
16+
17+
"configurations": [
18+
{
19+
"name": "static",
20+
"versions": [
21+
"TrashCanStatic"
22+
],
23+
"lflags-osx": [
24+
"-framework", "CoreServices"
25+
]
26+
},
27+
{
28+
"name": "dynamic",
29+
}
30+
]
1631
}

source/trashcan.d

+21-15
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,13 @@ private:
182182
alias int OSStatus;
183183
alias uint OptionBits;
184184

185-
extern(C) @nogc @system OSStatus _dummy_FSPathMakeRefWithOptions(const(char)* path, OptionBits, FSRef*, Boolean*) nothrow {return 0;}
186-
extern(C) @nogc @system OSStatus _dummy_FSMoveObjectToTrashSync(const(FSRef)*, FSRef*, OptionBits) nothrow {return 0;}
185+
version (TrashCanStatic) {
186+
extern(C) @nogc @system OSStatus FSPathMakeRefWithOptions(const(char)* path, OptionBits, FSRef*, Boolean*) nothrow;
187+
extern(C) @nogc @system OSStatus FSMoveObjectToTrashSync(const(FSRef)*, FSRef*, OptionBits) nothrow;
188+
} else {
189+
extern(C) @nogc @system OSStatus _dummy_FSPathMakeRefWithOptions(const(char)* path, OptionBits, FSRef*, Boolean*) nothrow {return 0;}
190+
extern(C) @nogc @system OSStatus _dummy_FSMoveObjectToTrashSync(const(FSRef)*, FSRef*, OptionBits) nothrow {return 0;}
191+
}
187192
}
188193

189194
/**
@@ -222,27 +227,28 @@ private:
222227
throw new Exception(format("SHFileOperation failed with error code %d", r));
223228
}
224229
} else version(OSX) {
225-
void* handle = dlopen("CoreServices.framework/Versions/A/CoreServices", RTLD_NOW | RTLD_LOCAL);
226-
if (handle !is null) {
230+
version (TrashCanStatic) {}
231+
else {
232+
void* handle = dlopen("CoreServices.framework/Versions/A/CoreServices", RTLD_NOW | RTLD_LOCAL);
233+
if (handle is null)
234+
throw new Exception(fromStringz(dlerror()).idup);
227235
scope(exit) dlclose(handle);
228236

229-
auto ptrFSPathMakeRefWithOptions = cast(typeof(&_dummy_FSPathMakeRefWithOptions))dlsym(handle, "FSPathMakeRefWithOptions");
230-
if (ptrFSPathMakeRefWithOptions is null) {
237+
auto FSPathMakeRefWithOptions = cast(typeof(&_dummy_FSPathMakeRefWithOptions))dlsym(handle, "FSPathMakeRefWithOptions");
238+
if (FSPathMakeRefWithOptions is null) {
231239
throw new Exception(fromStringz(dlerror()).idup);
232240
}
233241

234-
auto ptrFSMoveObjectToTrashSync = cast(typeof(&_dummy_FSMoveObjectToTrashSync))dlsym(handle, "FSMoveObjectToTrashSync");
235-
if (ptrFSMoveObjectToTrashSync is null) {
242+
auto FSMoveObjectToTrashSync = cast(typeof(&_dummy_FSMoveObjectToTrashSync))dlsym(handle, "FSMoveObjectToTrashSync");
243+
if (FSMoveObjectToTrashSync is null) {
236244
throw new Exception(fromStringz(dlerror()).idup);
237245
}
238-
239-
FSRef source;
240-
enforce(ptrFSPathMakeRefWithOptions(toStringz(path), 1, &source, null) == 0, "Could not make FSRef from path");
241-
FSRef target;
242-
enforce(ptrFSMoveObjectToTrashSync(&source, &target, 0) == 0, "Could not move path to trash");
243-
} else {
244-
throw new Exception(fromStringz(dlerror()).idup);
245246
}
247+
248+
FSRef source;
249+
enforce(FSPathMakeRefWithOptions(toStringz(path), 1, &source, null) == 0, "Could not make FSRef from path");
250+
FSRef target;
251+
enforce(FSMoveObjectToTrashSync(&source, &target, 0) == 0, "Could not move path to trash");
246252
} else {
247253
static if (isFreedesktop) {
248254
string dataPath = xdgDataHome(null, true);

0 commit comments

Comments
 (0)