Skip to content

Commit

Permalink
Add macos.
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed Jul 5, 2024
1 parent 3cfe3d2 commit 0ded182
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 122 deletions.
88 changes: 47 additions & 41 deletions .github/workflows/buildconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,81 @@ name: Build configuration matrix

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
config_matrix:
name: Build configuration matrix
defaults:
run:
working-directory: ${{github.workspace}}/tests/buildconfig
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
compiler: [g++, clang++-17]
exclude:
- os: macos-latest
compiler: clang++-17
env:
CXX: ${{ matrix.compiler }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt update
sudo apt install -y g++
- name: Install dependencies
if: ${{ matrix.os != 'macos-latest' }}
run: |
sudo apt update
sudo apt install -y g++
- name: Install newer Clang
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x ./llvm.sh
sudo ./llvm.sh 17
- name: Install newer Clang
if: ${{ matrix.os != 'macos-latest' }}
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x ./llvm.sh
sudo ./llvm.sh 17
- name: Default build
run: bash ci.sh
- name: Default build
run: bash ci.sh

- name: Emulator debug build
run: bash ci.sh -DRISCV_DEBUG=ON
- name: Emulator debug build
run: bash ci.sh -DRISCV_DEBUG=ON

- name: No threaded build
run: bash ci.sh -DRISCV_THREADED=OFF
- name: No threaded build
run: bash ci.sh -DRISCV_THREADED=OFF

- name: No extensions build
run: bash ci.sh -DRISCV_EXT_A=OFF -DRISCV_EXT_C=OFF -DRISCV_EXT_F=OFF
- name: No extensions build
run: bash ci.sh -DRISCV_EXT_A=OFF -DRISCV_EXT_C=OFF -DRISCV_EXT_F=OFF

- name: A-ext only build
run: bash ci.sh -DRISCV_EXT_A=ON -DRISCV_EXT_C=OFF -DRISCV_EXT_F=OFF
- name: A-ext only build
run: bash ci.sh -DRISCV_EXT_A=ON -DRISCV_EXT_C=OFF -DRISCV_EXT_F=OFF

- name: C-ext only build
run: bash ci.sh -DRISCV_EXT_A=OFF -DRISCV_EXT_C=ON -DRISCV_EXT_F=OFF
- name: C-ext only build
run: bash ci.sh -DRISCV_EXT_A=OFF -DRISCV_EXT_C=ON -DRISCV_EXT_F=OFF

- name: F-ext only build
run: bash ci.sh -DRISCV_EXT_A=OFF -DRISCV_EXT_C=OFF -DRISCV_EXT_F=ON
- name: F-ext only build
run: bash ci.sh -DRISCV_EXT_A=OFF -DRISCV_EXT_C=OFF -DRISCV_EXT_F=ON

- name: Experimental build
run: bash ci.sh -DRISCV_EXPERIMENTAL=ON -DRISCV_THREADED=OFF
- name: Experimental build
run: bash ci.sh -DRISCV_EXPERIMENTAL=ON -DRISCV_THREADED=OFF

- name: Experimental + threaded build
run: bash ci.sh -DRISCV_EXPERIMENTAL=ON -DRISCV_THREADED=ON
- name: Experimental + threaded build
run: bash ci.sh -DRISCV_EXPERIMENTAL=ON -DRISCV_THREADED=ON

- name: Experimental + threaded debug build
run: bash ci.sh -DRISCV_EXPERIMENTAL=ON -DRISCV_THREADED=ON -DRISCV_DEBUG=ON
- name: Experimental + threaded debug build
run: bash ci.sh -DRISCV_EXPERIMENTAL=ON -DRISCV_THREADED=ON -DRISCV_DEBUG=ON

- name: No multiprocessing build
run: bash ci.sh -DRISCV_EXPERIMENTAL=ON -DRISCV_MULTIPROCESS=OFF
- name: No multiprocessing build
run: bash ci.sh -DRISCV_EXPERIMENTAL=ON -DRISCV_MULTIPROCESS=OFF

- name: Multiprocessing debug build
run: bash ci.sh -DRISCV_EXPERIMENTAL=ON -DRISCV_MULTIPROCESS=ON -DRISCV_DEBUG=ON
- name: Multiprocessing debug build
run: bash ci.sh -DRISCV_EXPERIMENTAL=ON -DRISCV_MULTIPROCESS=ON -DRISCV_DEBUG=ON

- name: Binary translation build
run: bash ci.sh -DRISCV_BINARY_TRANSLATION=ON -DRISCV_DEBUG=OFF -DRISCV_EXT_C=OFF
- name: Binary translation build
run: bash ci.sh -DRISCV_BINARY_TRANSLATION=ON -DRISCV_DEBUG=OFF -DRISCV_EXT_C=OFF

- name: Binary translation debug build
run: bash ci.sh -DRISCV_BINARY_TRANSLATION=ON -DRISCV_DEBUG=ON -DRISCV_EXT_C=OFF
- name: Binary translation debug build
run: bash ci.sh -DRISCV_BINARY_TRANSLATION=ON -DRISCV_DEBUG=ON -DRISCV_EXT_C=OFF
12 changes: 12 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ add_library(riscv ${SOURCES})
if (COSMOPOLITAN)
target_compile_options(riscv PUBLIC -fexceptions)
endif()

if(APPLE)
find_library(SECURITY_FRAMEWORK Security)
find_library(FOUNDATION_FRAMEWORK Foundation)
mark_as_advanced(SECURITY_FRAMEWORK FOUNDATION_FRAMEWORK)

target_link_libraries(riscv PUBLIC
"${SECURITY_FRAMEWORK}"
"${FOUNDATION_FRAMEWORK}"
)
endif()

target_compile_features(riscv PUBLIC cxx_std_20)
target_include_directories(riscv PUBLIC .)
target_include_directories(riscv PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
Expand Down
29 changes: 28 additions & 1 deletion lib/libriscv/linux/syscalls_poll.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
#if defined(__APPLE__)
#include <time.h>
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
#else
#include <sys/time.h>
#endif

#include <poll.h>

int poll_with_timeout(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts) {
#ifdef __linux__
return ppoll(fds, nfds, timeout_ts, NULL);
#elif __APPLE__
// On macOS, we don't have ppoll, so we need to use poll and then handle the timeout manually.
int timeout_ms;
if (timeout_ts != NULL) {
timeout_ms = timeout_ts->tv_sec * 1000 + timeout_ts->tv_nsec / 1000000;
} else {
timeout_ms = -1;
}
return poll(fds, nfds, timeout_ms);
#else
#error "Unknown compiler"
#endif
}

// int ppoll(struct pollfd *fds, nfds_t nfds,
// const struct timespec *timeout_ts, const sigset_t *sigmask);
template <int W>
Expand Down Expand Up @@ -30,7 +57,7 @@ static void syscall_ppoll(Machine<W>& machine)
linux_fds[i].fd = machine.fds().translate(fds[i].fd);
}

const int res = ppoll(linux_fds.data(), nfds, &ts, NULL);
const int res = poll_with_timeout(linux_fds.data(), nfds, &ts);
// The ppoll system call modifies TS
//clock_gettime(CLOCK_MONOTONIC, &ts);
//machine.copy_to_guest(g_ts, &ts, sizeof(ts));
Expand Down
Loading

0 comments on commit 0ded182

Please sign in to comment.