-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable Dylib loading code in SwiftBundlerRuntime on Linux until impl…
…emented
- Loading branch information
1 parent
5ba9c04
commit d5b56cf
Showing
2 changed files
with
61 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
import Darwin | ||
import Foundation | ||
|
||
#if !canImport(Darwin) | ||
#error("Dylib only implemented for Darwin") | ||
#endif | ||
#if canImport(Darwin) | ||
import Darwin | ||
|
||
/// A dynamic library. | ||
public struct Dylib { | ||
private var dylib: UnsafeMutableRawPointer | ||
/// A dynamic library. | ||
public struct Dylib { | ||
private var dylib: UnsafeMutableRawPointer | ||
|
||
/// Opens the dynamic library at the provided path. | ||
public static func open(_ path: URL) throws -> Dylib { | ||
guard let dylib = dlopen(path.path, RTLD_NOW | RTLD_LOCAL) else { | ||
throw DylibError.failedToOpen | ||
/// Opens the dynamic library at the provided path. | ||
public static func open(_ path: URL) throws -> Dylib { | ||
guard let dylib = dlopen(path.path, RTLD_NOW | RTLD_LOCAL) else { | ||
throw DylibError.failedToOpen | ||
} | ||
return Dylib(dylib: dylib) | ||
} | ||
return Dylib(dylib: dylib) | ||
} | ||
|
||
/// Retrieves a symbol from a dynamic library. Protects against the symbol not | ||
/// existing, but doesn't protect against type mismatches. | ||
public func symbol<T>(named name: String, ofType type: T.Type) -> T? { | ||
guard let symbolPointer = dlsym(dylib, name) else { | ||
return nil | ||
/// Retrieves a symbol from a dynamic library. Protects against the symbol not | ||
/// existing, but doesn't protect against type mismatches. | ||
public func symbol<T>(named name: String, ofType type: T.Type) -> T? { | ||
guard let symbolPointer = dlsym(dylib, name) else { | ||
return nil | ||
} | ||
return unsafeBitCast(symbolPointer, to: T.self) | ||
} | ||
return unsafeBitCast(symbolPointer, to: T.self) | ||
} | ||
|
||
public func close() { | ||
dlclose(dylib) | ||
public func close() { | ||
dlclose(dylib) | ||
} | ||
} | ||
} | ||
|
||
public enum DylibError: LocalizedError { | ||
case failedToOpen | ||
public enum DylibError: LocalizedError { | ||
case failedToOpen | ||
|
||
public var errorDescription: String? { | ||
switch self { | ||
case .failedToOpen: | ||
return "Failed to open dynamic library" | ||
public var errorDescription: String? { | ||
switch self { | ||
case .failedToOpen: | ||
return "Failed to open dynamic library" | ||
} | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters