support building for macOS and non-linux unixes

Also updates build.yml to add macOS runners
This commit is contained in:
Luke Usher 2024-02-08 15:20:42 +00:00 committed by Luke Usher
parent b7f62dc378
commit 7f0f985a14
3 changed files with 40 additions and 22 deletions

View file

@ -14,7 +14,7 @@ jobs:
build: build:
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, windows-latest] os: [ubuntu-latest, windows-latest, macos-latest]
profile: ['debug', 'release', 'optimized'] profile: ['debug', 'release', 'optimized']
fail-fast: false fail-fast: false
runs-on: ${{ matrix.os }} 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; typedef HMODULE _LIBRASHADER_IMPL_HANDLE;
#define _LIBRASHADER_LOAD LoadLibraryW(L"librashader.dll") #define _LIBRASHADER_LOAD LoadLibraryW(L"librashader.dll")
#elif defined(__APPLE__)
#elif defined(__linux__) #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> #include <dlfcn.h>
#define _LIBRASHADER_ASSIGN(HMOD, INSTANCE, NAME) \ #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. /// \return An `libra_instance_t` struct with loaded function pointers.
libra_instance_t librashader_load_instance(); 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() { libra_instance_t librashader_load_instance() {
_LIBRASHADER_IMPL_HANDLE librashader = _LIBRASHADER_LOAD; _LIBRASHADER_IMPL_HANDLE librashader = _LIBRASHADER_LOAD;
libra_instance_t instance = __librashader_make_null_instance(); libra_instance_t instance = __librashader_make_null_instance();

View file

@ -66,7 +66,15 @@ pub fn main() {
.expect("Unable to write bindings."); .expect("Unable to write bindings.");
println!("Moving artifacts..."); 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"]; let artifacts = &["liblibrashader_capi.so", "liblibrashader_capi.a"];
for artifact in artifacts { for artifact in artifacts {
let ext = artifact.strip_prefix("lib").unwrap(); let ext = artifact.strip_prefix("lib").unwrap();