Merge pull request #36 from LukeUsher/master

build: support building for macOS and non-linux unixes
This commit is contained in:
Ronny Chan 2024-02-08 21:16:20 -05:00 committed by GitHub
commit 6d4e6590de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 22 deletions

View file

@ -14,7 +14,7 @@ jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest, windows-latest, macos-latest]
profile: ['debug', 'release', 'optimized']
fail-fast: false
runs-on: ${{ matrix.os }}

View file

@ -48,8 +48,18 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}
typedef HMODULE _LIBRASHADER_IMPL_HANDLE;
#define _LIBRASHADER_LOAD LoadLibraryW(L"librashader.dll")
#elif defined(__linux__)
#elif defined(__APPLE__)
#include <dlfcn.h>
#define _LIBRASHADER_ASSIGN(HMOD, INSTANCE, NAME) \
{ \
void *address = dlsym(HMOD, "libra_" #NAME); \
if (address != NULL) { \
(INSTANCE).NAME = (PFN_libra_##NAME)address; \
} \
}
typedef void* _LIBRASHADER_IMPL_HANDLE;
#define _LIBRASHADER_LOAD dlopen("librashader.dylib", RTLD_LAZY)
#elif defined(__unix__) || defined (__linux__)
#include <dlfcn.h>
#define _LIBRASHADER_ASSIGN(HMOD, INSTANCE, NAME) \
{ \
@ -990,7 +1000,7 @@ libra_instance_t __librashader_make_null_instance() {
/// \return An `libra_instance_t` struct with loaded function pointers.
libra_instance_t librashader_load_instance();
#if defined(_WIN32) || defined(__linux__)
#if defined(_WIN32) || defined(__linux__) || defined(__unix__) || defined(__APPLE__)
libra_instance_t librashader_load_instance() {
_LIBRASHADER_IMPL_HANDLE librashader = _LIBRASHADER_LOAD;
libra_instance_t instance = __librashader_make_null_instance();

View file

@ -66,7 +66,15 @@ pub fn main() {
.expect("Unable to write bindings.");
println!("Moving artifacts...");
if cfg!(target_os = "linux") {
if cfg!(target_os = "macos") {
let artifacts = &["liblibrashader_capi.dylib", "liblibrashader_capi.a"];
for artifact in artifacts {
let ext = artifact.strip_prefix("lib").unwrap();
let ext = ext.replace("_capi", "");
fs::rename(output_dir.join(artifact), output_dir.join(ext)).unwrap();
}
}
else if cfg!(target_family = "unix") {
let artifacts = &["liblibrashader_capi.so", "liblibrashader_capi.a"];
for artifact in artifacts {
let ext = artifact.strip_prefix("lib").unwrap();