Skip to content

Commit 16fcb7d

Browse files
committed
add bsd ci
1 parent a824bf9 commit 16fcb7d

File tree

9 files changed

+290
-6
lines changed

9 files changed

+290
-6
lines changed

.github/workflows/dragonflybsd.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: DragonflyBSD
2+
3+
on:
4+
pull_request:
5+
push:
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
concurrency:
15+
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-DragonflyBSD
16+
cancel-in-progress: true
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
submodules: true
21+
22+
- name: Tests
23+
id: test
24+
uses: vmactions/dragonflybsd-vm@v1
25+
with:
26+
usesh: true
27+
prepare: |
28+
pkg install -y socat git gmake bash
29+
run: |
30+
cd $GITHUB_WORKSPACE
31+
./configure
32+
gmake -j4
33+
gmake run
34+

.github/workflows/freebsd.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: FreeBSD
2+
3+
on:
4+
pull_request:
5+
push:
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
concurrency:
15+
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-FreeBSD
16+
cancel-in-progress: true
17+
steps:
18+
- uses: actions/checkout@v2
19+
with:
20+
submodules: true
21+
22+
- name: Tests
23+
uses: vmactions/freebsd-vm@v1
24+
with:
25+
usesh: true
26+
mem: 4096
27+
copyback: false
28+
prepare: pkg install -y git curl unzip gmake llvm gsed bash perl5
29+
run: |
30+
./configure
31+
gmake -j4
32+
gmake run
33+

.github/workflows/netbsd.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: NetBSD
2+
3+
on:
4+
pull_request:
5+
push:
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
concurrency:
15+
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-NetBSD
16+
cancel-in-progress: true
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
submodules: true
21+
22+
- name: Tests
23+
id: test
24+
uses: vmactions/netbsd-vm@v1
25+
with:
26+
usesh: true
27+
prepare: |
28+
/usr/sbin/pkg_add curl bash git gmake
29+
run: |
30+
cd $GITHUB_WORKSPACE
31+
./configure
32+
gmake -j4
33+
gmake run
34+

.github/workflows/openbsd.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: OpenBSD
2+
3+
on:
4+
pull_request:
5+
push:
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
concurrency:
15+
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-OpenBSD
16+
cancel-in-progress: true
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
submodules: true
21+
22+
- name: Tests
23+
id: test
24+
uses: vmactions/openbsd-vm@v1
25+
with:
26+
usesh: true
27+
prepare: |
28+
pkg_add curl git gmake bash gcc
29+
ln -sf /usr/local/bin/gmake /usr/local/bin/make || true
30+
run: |
31+
cd $GITHUB_WORKSPACE
32+
./configure
33+
gmake -j4
34+
gmake run
35+

.github/workflows/solaris.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Solaris
2+
3+
on:
4+
pull_request:
5+
push:
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
concurrency:
15+
group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-Solaris
16+
cancel-in-progress: true
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
submodules: true
21+
22+
- name: Tests
23+
id: test
24+
uses: vmactions/solaris-vm@v1
25+
with:
26+
usesh: true
27+
prepare: |
28+
pkgutil -y -i socat git gmake bash gcc4g++ || pkgutil -y -i socat git gmake bash gcc5g++ || pkg install -y developer/gcc || true
29+
run: |
30+
cd $GITHUB_WORKSPACE
31+
bash ./configure
32+
gmake -j4
33+
gmake run
34+

configure

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,11 @@ case "${os_host}" in
687687
*darwin*) os_host="macosx" ;;
688688
*linux*) os_host="linux" ;;
689689
*freebsd*) os_host="freebsd" ;;
690+
*netbsd*) os_host="netbsd" ;;
691+
*openbsd*) os_host="openbsd" ;;
692+
*dragonfly*) os_host="dragonflybsd" ;;
690693
*bsd*) os_host="bsd" ;;
694+
*sunos*) os_host="solaris" ;;
691695
*haiku*) os_host="haiku" ;;
692696
esac
693697

@@ -724,7 +728,7 @@ fi
724728
_target_plat_default=${os_host}
725729
if is_host "msys"; then
726730
_target_plat_default="mingw"
727-
elif is_host "freebsd"; then
731+
elif is_host "freebsd" "openbsd" "dragonflybsd" "netbsd"; then
728732
_target_plat_default="bsd"
729733
elif test_nz "${EMSDK}"; then
730734
_target_plat_default="wasm"
@@ -756,7 +760,7 @@ _target_mode_default="release"
756760
_target_kind_default="static"
757761

758762
# set the default project generator and build program
759-
if is_host "freebsd" "bsd"; then
763+
if is_host "freebsd" "netbsd" "openbsd" "dragonflybsd" "bsd" "solaris"; then
760764
project_generator="gmake"
761765
_make_program_default="gmake"
762766
_ninja_program_default="ninja"

src/tbox/platform/posix/sched_affinity.c

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include <string.h>
2828
#include <sched.h>
2929
#include <sys/types.h>
30+
#ifdef __NetBSD__
31+
#include <sys/cpuset.h>
32+
#include <stdlib.h>
33+
#endif
3034

3135
/* //////////////////////////////////////////////////////////////////////////////////////
3236
* implementation
@@ -36,7 +40,28 @@ tb_bool_t tb_sched_setaffinity(tb_size_t pid, tb_cpuset_ref_t cpuset)
3640
// check
3741
tb_assert_and_check_return_val(cpuset, tb_false);
3842

39-
// set cpu affinity
43+
#ifdef __NetBSD__
44+
// NetBSD uses cpuset_t API
45+
cpuset_t *cpu_set;
46+
size_t size;
47+
if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (pid_t)pid, sizeof(cpuset_t), NULL, &size) != 0)
48+
return tb_false;
49+
cpu_set = (cpuset_t *)malloc(size);
50+
if (!cpu_set)
51+
return tb_false;
52+
cpuset_zero(cpu_set);
53+
54+
tb_int_t i;
55+
for (i = 0; i < TB_CPUSET_SIZE; i++)
56+
{
57+
if (TB_CPUSET_ISSET(i, cpuset))
58+
cpuset_set(i, cpu_set);
59+
}
60+
tb_bool_t ok = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (pid_t)pid, size, cpu_set) == 0;
61+
free(cpu_set);
62+
return ok;
63+
#else
64+
// Linux uses cpu_set_t API
4065
tb_int_t i;
4166
cpu_set_t cpu_set;
4267
CPU_ZERO(&cpu_set);
@@ -46,13 +71,41 @@ tb_bool_t tb_sched_setaffinity(tb_size_t pid, tb_cpuset_ref_t cpuset)
4671
CPU_SET(i, &cpu_set);
4772
}
4873
return sched_setaffinity((pid_t)pid, sizeof(cpu_set_t), &cpu_set) == 0;
74+
#endif
4975
}
5076
tb_bool_t tb_sched_getaffinity(tb_size_t pid, tb_cpuset_ref_t cpuset)
5177
{
5278
// check
5379
tb_assert_and_check_return_val(cpuset, tb_false);
5480

55-
// get cpu affinity
81+
#ifdef __NetBSD__
82+
// NetBSD uses cpuset_t API
83+
cpuset_t *cpu_set;
84+
size_t size;
85+
if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (pid_t)pid, sizeof(cpuset_t), NULL, &size) != 0)
86+
return tb_false;
87+
cpu_set = (cpuset_t *)malloc(size);
88+
if (!cpu_set)
89+
return tb_false;
90+
91+
if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (pid_t)pid, size, cpu_set, NULL) != 0)
92+
{
93+
free(cpu_set);
94+
return tb_false;
95+
}
96+
97+
// save cpuset
98+
tb_int_t i;
99+
TB_CPUSET_ZERO(cpuset);
100+
for (i = 0; i < TB_CPUSET_SIZE; i++)
101+
{
102+
if (cpuset_isset(i, cpu_set))
103+
TB_CPUSET_SET(i, cpuset);
104+
}
105+
free(cpu_set);
106+
return tb_true;
107+
#else
108+
// Linux uses cpu_set_t API
56109
cpu_set_t cpu_set;
57110
CPU_ZERO(&cpu_set);
58111
if (sched_getaffinity((pid_t)pid, sizeof(cpu_set_t), &cpu_set) != 0)
@@ -67,4 +120,5 @@ tb_bool_t tb_sched_getaffinity(tb_size_t pid, tb_cpuset_ref_t cpuset)
67120
TB_CPUSET_SET(i, cpuset);
68121
}
69122
return tb_true;
123+
#endif
70124
}

src/tbox/platform/posix/thread_affinity.c

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include "../thread.h"
2828
#include <pthread.h>
2929
#include <string.h>
30+
#ifdef __NetBSD__
31+
#include <sys/cpuset.h>
32+
#include <stdlib.h>
33+
#endif
3034

3135
/* //////////////////////////////////////////////////////////////////////////////////////
3236
* implementation
@@ -39,7 +43,28 @@ tb_bool_t tb_thread_setaffinity(tb_thread_ref_t thread, tb_cpuset_ref_t cpuset)
3943
// get thread
4044
pthread_t pthread = thread? *((pthread_t*)thread) : pthread_self();
4145

42-
// set cpu affinity
46+
#ifdef __NetBSD__
47+
// NetBSD uses cpuset_t API
48+
cpuset_t *cpu_set;
49+
size_t size;
50+
if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), NULL, &size) != 0)
51+
return tb_false;
52+
cpu_set = (cpuset_t *)malloc(size);
53+
if (!cpu_set)
54+
return tb_false;
55+
cpuset_zero(cpu_set);
56+
57+
tb_int_t i;
58+
for (i = 0; i < TB_CPUSET_SIZE; i++)
59+
{
60+
if (TB_CPUSET_ISSET(i, cpuset))
61+
cpuset_set(i, cpu_set);
62+
}
63+
tb_bool_t ok = pthread_setaffinity_np(pthread, size, cpu_set) == 0;
64+
free(cpu_set);
65+
return ok;
66+
#else
67+
// Linux uses cpu_set_t API
4368
tb_int_t i;
4469
cpu_set_t cpu_set;
4570
CPU_ZERO(&cpu_set);
@@ -49,6 +74,7 @@ tb_bool_t tb_thread_setaffinity(tb_thread_ref_t thread, tb_cpuset_ref_t cpuset)
4974
CPU_SET(i, &cpu_set);
5075
}
5176
return pthread_setaffinity_np(pthread, sizeof(cpu_set_t), &cpu_set) == 0;
77+
#endif
5278
}
5379
tb_bool_t tb_thread_getaffinity(tb_thread_ref_t thread, tb_cpuset_ref_t cpuset)
5480
{
@@ -58,7 +84,34 @@ tb_bool_t tb_thread_getaffinity(tb_thread_ref_t thread, tb_cpuset_ref_t cpuset)
5884
// get thread
5985
pthread_t pthread = thread? *((pthread_t*)thread) : pthread_self();
6086

61-
// get cpu affinity
87+
#ifdef __NetBSD__
88+
// NetBSD uses cpuset_t API
89+
cpuset_t *cpu_set;
90+
size_t size;
91+
if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), NULL, &size) != 0)
92+
return tb_false;
93+
cpu_set = (cpuset_t *)malloc(size);
94+
if (!cpu_set)
95+
return tb_false;
96+
97+
if (pthread_getaffinity_np(pthread, size, cpu_set) != 0)
98+
{
99+
free(cpu_set);
100+
return tb_false;
101+
}
102+
103+
// save cpuset
104+
tb_int_t i;
105+
TB_CPUSET_ZERO(cpuset);
106+
for (i = 0; i < TB_CPUSET_SIZE; i++)
107+
{
108+
if (cpuset_isset(i, cpu_set))
109+
TB_CPUSET_SET(i, cpuset);
110+
}
111+
free(cpu_set);
112+
return tb_true;
113+
#else
114+
// Linux uses cpu_set_t API
62115
cpu_set_t cpu_set;
63116
CPU_ZERO(&cpu_set);
64117
if (pthread_getaffinity_np(pthread, sizeof(cpu_set_t), &cpu_set) != 0)
@@ -73,4 +126,5 @@ tb_bool_t tb_thread_getaffinity(tb_thread_ref_t thread, tb_cpuset_ref_t cpuset)
73126
TB_CPUSET_SET(i, cpuset);
74127
}
75128
return tb_true;
129+
#endif
76130
}

src/xmake.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ if is_plat "mingw" "msys" "cygwin"; then
3737
add_syslinks "ws2_32" "pthread" "m"
3838
elif is_plat "haiku"; then
3939
add_syslinks "pthread" "network" "m" "c"
40+
elif is_plat "bsd" "solaris"; then
41+
add_syslinks "pthread" "m"
4042
else
4143
add_syslinks "pthread" "dl" "m" "c"
4244
fi

0 commit comments

Comments
 (0)