Skip to content

Commit bfbdcc7

Browse files
authored
macOS Support (#3)
* macos * fix linux build * combine ci jobs * no macos-xlarge :/ * fix path * readme
1 parent 5ba0687 commit bfbdcc7

File tree

20 files changed

+367
-108
lines changed

20 files changed

+367
-108
lines changed

.github/workflows/build.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- main
6+
tags:
7+
- '*'
8+
pull_request:
9+
jobs:
10+
windows:
11+
runs-on: windows-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
- name: Configure
16+
run: cmake -S . -B build -DRPP_TEST=ON
17+
- name: Build
18+
run: cmake --build build --config Release
19+
- name: Test
20+
run: ctest --test-dir build -C Release --output-on-failure
21+
linux:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
- name: Install Clang 17
27+
run: |
28+
wget https://apt.llvm.org/llvm.sh
29+
chmod +x ./llvm.sh
30+
sudo ./llvm.sh 17
31+
- name: Configure
32+
run: CXX=clang++-17 cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DRPP_TEST=ON
33+
- name: Build
34+
run: cmake --build build -- -j
35+
- name: Test
36+
run: ctest --test-dir build --output-on-failure
37+
macos:
38+
runs-on: macos-latest
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v4
42+
- name: Install Clang 17
43+
run: brew install llvm@17
44+
- name: Configure
45+
run: CXX=/usr/local/opt/llvm/bin/clang++ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DRPP_TEST=ON
46+
- name: Build
47+
run: cmake --build build -- -j
48+
- name: Test
49+
run: ctest --test-dir build --output-on-failure

.github/workflows/ubuntu.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/windows.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ To use rpp with another build system, add `rpp` to your include path, add `rpp/r
3333

3434
## Platform Support
3535

36-
Only the following configurations are supported:
36+
The following configurations are supported:
3737

38-
| OS | Compiler | Arch |
39-
|---------|-------------|------|
40-
| Windows | MSVC 19.37+ | x64 |
41-
| Linux | Clang 17+ | Any |
38+
| OS | Compiler | Arch |
39+
|---------|-------------|--------------|
40+
| Windows | MSVC 19.37+ | x64 |
41+
| Linux | Clang 17+ | Any |
42+
| macOS | Clang 17+ | x64, aarch64 |
4243

4344
Note that aside from MSVC on Windows, the [gcc vector extensions](https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html) (which are [implemented by clang](https://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors)) are used to implement the SIMD operations. See `rpp/rpp/impl/simd.cpp`.
4445

45-
Other configurations (macOS, GCC, etc.) may be added in the future.
46+
Other configurations (GCC, etc.) may be added in the future.
4647

4748
## Examples
4849

rpp/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ endif()
5454

5555
if(WIN32)
5656
set(SOURCES_RPP ${SOURCES_RPP} "w32/w32_util.h" "w32/unify.cpp")
57-
elseif(LINUX)
57+
elseif(LINUX OR APPLE)
5858
set(SOURCES_RPP ${SOURCES_RPP} "pos/unify.cpp")
5959
else()
60-
message(FATAL_ERROR "Unsupported platform: only Windows and Linux are supported.")
60+
message(FATAL_ERROR "Unsupported OS: only Windows, Linux, and macOS are supported.")
6161
endif()
6262

6363
add_library(rpp STATIC ${SOURCES_RPP})
@@ -76,7 +76,8 @@ set_property(TARGET rpp PROPERTY INTERPROCEDURAL_OPTIMIZATION
7676
$<$<CONFIG:Release>:TRUE>
7777
$<$<CONFIG:MinSizeRel>:TRUE>)
7878

79-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
79+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
80+
CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
8081
set(CLANG TRUE)
8182
endif()
8283

@@ -103,7 +104,8 @@ if(MSVC)
103104
target_compile_options(rpp PRIVATE /MP /W4 /GR- /GS- /EHa- /wd4201)
104105

105106
elseif(CLANG)
106-
if(CLANG_VERSION_MAJOR LESS 17)
107+
if((LINUX AND CLANG_VERSION_MAJOR LESS 17) OR
108+
(APPLE AND CMAKE_CXX_COMPILER_VERSION LESS 17))
107109
message(FATAL_ERROR "Unsupported Clang version: only 17+ is supported.")
108110
endif()
109111

rpp/async.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,20 +251,28 @@ struct Event {
251251

252252
#ifdef RPP_OS_WINDOWS
253253
[[nodiscard]] static Event of_sys(void* event) noexcept;
254-
#else
254+
#elif defined RPP_OS_LINUX
255255
[[nodiscard]] static Event of_sys(i32 fd, i32 mask) noexcept;
256+
#elif defined RPP_OS_MACOS
257+
[[nodiscard]] static Event of_sys(i32 fd, i16 mask) noexcept;
256258
#endif
257259

258260
private:
259261
#ifdef RPP_OS_WINDOWS
260262
Event(void* event) noexcept : event_{event} {
261263
}
262264
void* event_ = null;
263-
#else
265+
#elif defined RPP_OS_LINUX
264266
Event(i32 fd, i32 mask) noexcept : fd{fd}, mask{mask} {
265267
}
266268
i32 fd = -1;
267269
i32 mask = 0;
270+
#elif defined RPP_OS_MACOS
271+
Event(i32 fd, i16 mask) noexcept : fd{fd}, mask{mask} {
272+
}
273+
i32 fd = -1;
274+
i32 signal_fd = -1;
275+
i16 mask = 0;
268276
#endif
269277
};
270278

rpp/base.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@
5151
#define RPP_OS_LINUX
5252
#include <pthread.h>
5353

54+
#elif defined __APPLE__
55+
56+
#define RPP_OS_MACOS
57+
#include <pthread.h>
58+
5459
#else
55-
#error "Unsupported OS: only Windows and Linux are supported."
60+
#error "Unsupported OS: only Windows, Linux, and macOS are supported."
5661
#endif
5762

5863
#if defined __x86_64__ || defined _M_X64

rpp/impl/log.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <windows.h>
1212
#endif
1313

14-
#ifdef RPP_OS_LINUX
14+
#if defined RPP_OS_LINUX || defined RPP_OS_MACOS
1515
#include <errno.h>
1616
#include <signal.h>
1717
#endif
@@ -82,7 +82,12 @@ void debug_break() noexcept {
8282
[[nodiscard]] String_View sys_error() noexcept {
8383
constexpr int buffer_size = 256;
8484
static thread_local char buffer[buffer_size];
85+
#ifdef RPP_OS_MACOS
86+
assert(strerror_r(errno, buffer, buffer_size) == 0);
87+
return String_View{buffer};
88+
#else
8589
return String_View{strerror_r(errno, buffer, buffer_size)};
90+
#endif
8691
}
8792

8893
void debug_break() noexcept {

rpp/impl/profile.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ void Profile::finalize() noexcept {
212212
}
213213
finalizers.~Vec();
214214
}
215-
unregister_thread();
216-
this_thread.~Thread_Profile();
215+
this_thread.finalize();
217216
{
218217
Thread::Lock lock(allocs_lock);
219218
for(auto& prof : allocs) {

rpp/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "base.h"
55

6-
#ifdef RPP_OS_LINUX
6+
#if defined RPP_OS_LINUX || defined RPP_OS_MACOS
77
#include <netinet/in.h>
88
#include <sys/socket.h>
99
#endif

0 commit comments

Comments
 (0)