Skip to content

Commit

Permalink
fix build on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
Dillonb committed Sep 4, 2024
1 parent b9121e9 commit 12151ed
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 15 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,16 @@ else()
endif()
endif()

if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
set (X86 TRUE)
else ()
set (X86 FALSE)
endif ()

check_c_compiler_flag("-mssse3" HAS_SSSE3)
check_c_compiler_flag("-msse4.1" HAS_SSE4_1)

if (HAS_SSSE3 AND HAS_SSE4_1)
if (HAS_SSSE3 AND HAS_SSE4_1 AND X86)
set(DEFAULT_C_COMP_OPTIONS ${DEFAULT_C_COMP_OPTIONS} -mssse3 -msse4.1)
ADD_COMPILE_DEFINITIONS(N64_HAVE_SSE)
endif()
Expand Down
14 changes: 11 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
pkgs.mold-wrapped
n64-tools.packages.${system}.bass
n64-tools.packages.${system}.chksum64
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
pkgs.clang_18
];

libs = [
pkgs.SDL2
pkgs.capstone
pkgs.dbus
pkgs.bzip2
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.Cocoa
];
in
{
Expand All @@ -57,9 +61,13 @@
(pkgs.lib.cmakeFeature "CMAKE_BUILD_TYPE" "Release")
];
passthru.exePath = "/bin/n64";
postInstall = ''
wrapProgram $out/bin/n64 --set LD_LIBRARY_PATH ${pkgs.vulkan-loader}/lib
'';
postInstall =
if pkgs.stdenv.isLinux then ''
wrapProgram $out/bin/n64 --set LD_LIBRARY_PATH ${pkgs.vulkan-loader}/lib
'' else if pkgs.stdenv.isDarwin then ''
wrapProgram $out/bin/n64 --set DYLD_FALLBACK_LIBRARY_PATH ${pkgs.darwin.moltenvk}/lib
'' else throw "Unsupported platform";

};

apps.default = {
Expand Down
8 changes: 4 additions & 4 deletions src/common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ typedef __m128i s128;
#define ASSERTDWORD(type) _Static_assert(sizeof(type) == 8, #type " must be 64 bits")
#endif

#ifndef N64_WIN
#if defined(N64_WIN) || defined(N64_MACOS)
#define PATH_MAX 0x1000
#else
#include <unistd.h>
#include <linux/limits.h>
#else
#define PATH_MAX 0x1000
#endif


Expand All @@ -69,7 +69,7 @@ INLINE u32 npow2(u32 x) {
}

INLINE bool file_exists(const char* path) {
#ifndef N64_WIN
#if !defined(N64_WIN) && !defined(N64_MACOS)
return access(path, F_OK) == 0;
#else
FILE* f = fopen(path, "r");
Expand Down
2 changes: 1 addition & 1 deletion src/cpu/fpu_instructions.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void set_cause_cvt_l_d(double d) {
#define check_nans_f(fs, ft) do { assert_is_float(fs); assert_is_float(ft); if (is_nan_f(fs) || is_nan_f(ft)) { set_cause_invalid_operation(); check_fpu_exception(); } } while (0)
#define check_nans_d(fs, ft) do { assert_is_double(fs); assert_is_double(ft); if (is_nan_d(fs) || is_nan_d(ft)) { set_cause_invalid_operation(); check_fpu_exception(); } } while (0)

#ifdef N64_WIN
#if defined(N64_WIN) || defined(N64_MACOS)
#define unordered_s(a, b) (isnan(a) || isnan(b))
#define unordered_d(a, b) (isnan(a) || isnan(b))
#else
Expand Down
2 changes: 2 additions & 0 deletions src/system/mprotect_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void mprotect_rwx(u8* cache, size_t size, const char* cache_name) {
if (!VirtualProtect(cache, size, PAGE_EXECUTE_READWRITE, &oldProtect)) {
mprotect_error(cache_name);
}
#elif defined(N64_MACOS)
// no-op
#else
if (mprotect(cache, size, PROT_READ | PROT_WRITE | PROT_EXEC) != 0) {
mprotect_error(cache_name);
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dynarec_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void test_branch_likely(bool jit) {
n64_system_step(false, 1);

assert_reg_value((u64)0, MIPS_REG_T0);
assert_eq_u64("pc", 0xFFFFFFFF80000008, N64CPU.pc);
assert_eq_u64("pc", 0xFFFFFFFF80000008ULL, N64CPU.pc);

if (jit) {
n64_system_step(true, -1);
Expand All @@ -48,7 +48,7 @@ void test_branch_likely(bool jit) {
}

// Branch was NOT taken.
assert_eq_u64("pc", 0xFFFFFFFF80000014, N64CPU.pc);
assert_eq_u64("pc", 0xFFFFFFFF80000014ULL, N64CPU.pc);

// Delay slot was skipped.
// 0: register is not getting written back at all
Expand Down
9 changes: 5 additions & 4 deletions tests/unit.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef N64_UNIT_H
#define N64_UNIT_H
#include <cpu/r4300i_register_access.h>
#include <inttypes.h>

static int tests_failed = 0;

Expand Down Expand Up @@ -62,9 +63,9 @@ void test_instr_1_1_imm(case_instr_1_1_imm test_case, mipsinstr_handler_t instr,
u64 actual = get_register(routput);

if (actual != test_case.output) {
failed("%s: r%d, (r%d)%ld, %d | Expected: %ld but got %ld", instr_name, routput, rinput, test_case.input, test_case.immediate, test_case.output, actual)
failed("%s: r%d, (r%d)%" PRId64 ", %d | Expected: %" PRId64 " but got %" PRId64, instr_name, routput, rinput, test_case.input, test_case.immediate, test_case.output, actual)
} else if (SHOULD_LOG_PASSED_TESTS) {
passed("%s: r%d, (r%d)%ld, %d | Expected: %ld and got %ld", instr_name, routput, rinput, test_case.input, test_case.immediate, test_case.output, actual)
passed("%s: r%d, (r%d)%" PRId64 ", %d | Expected: %" PRId64 " and got %" PRId64, instr_name, routput, rinput, test_case.input, test_case.immediate, test_case.output, actual)
}
}

Expand All @@ -88,9 +89,9 @@ void test_instr_2_1(case_instr_2_1 test_case, mipsinstr_handler_t instr, const c
u64 actual = get_register(routput);

if (actual != test_case.output) {
failed("%s: r%d, (r%d)%ld, (r%d)%ld | Expected: %ld but got %ld", instr_name, routput, rinput1, test_case.r1, rinput2, test_case.r2, test_case.output, actual)
failed("%s: r%d, (r%d)%" PRId64 ", (r%d)%" PRId64 " | Expected: %" PRId64 " but got %" PRId64, instr_name, routput, rinput1, test_case.r1, rinput2, test_case.r2, test_case.output, actual)
} else if (SHOULD_LOG_PASSED_TESTS) {
passed("%s: r%d, (r%d)%ld, (r%d)%ld | Expected: %ld and got %ld", instr_name, routput, rinput1, test_case.r1, rinput2, test_case.r2, test_case.output, actual)
passed("%s: r%d, (r%d)%" PRId64 ", (r%d)%" PRId64 " | Expected: %" PRId64 " and got %" PRId64, instr_name, routput, rinput1, test_case.r1, rinput2, test_case.r2, test_case.output, actual)
}
}

Expand Down

0 comments on commit 12151ed

Please sign in to comment.