Merge pull request #7 from birth-software/support-macos

Support MacOS
This commit is contained in:
David 2024-07-05 08:07:06 +02:00 committed by GitHub
commit 226de05c6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 97 additions and 46 deletions

View File

@ -8,10 +8,8 @@ on:
schedule: schedule:
- cron: "0 0 * * *" - cron: "0 0 * * *"
env:
TIMEOUT_MINUTES: 15
jobs: jobs:
build_and_test: linux_build_and_test:
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
timeout-minutes: 15 timeout-minutes: 15
steps: steps:
@ -19,5 +17,13 @@ jobs:
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Build and test - name: Build and test
run: | run: |
set -ex ./run_tests.sh
macos_build_and_test:
runs-on: macos-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and test
run: |
./run_tests.sh ./run_tests.sh

View File

@ -81,6 +81,19 @@ forceinline fn u8 mem_equal_range(T* a, T* b, u64 count)
return memcmp(a, b, count * sizeof(T)) == 0; return memcmp(a, b, count * sizeof(T)) == 0;
} }
fn u8 memeq(u8* a, u8* b, u64 size)
{
for (u64 i = 0; i < size; i += 1)
{
if (a[i] != b[i])
{
return 0;
}
}
return 1;
}
template<typename T> template<typename T>
struct Slice struct Slice
{ {
@ -241,6 +254,7 @@ struct StaticList
// return (Hash)result; // return (Hash)result;
// } // }
#ifdef __linux__
// fn forceinline long syscall0(long n) // fn forceinline long syscall0(long n)
// { // {
// unsigned long ret; // unsigned long ret;
@ -301,18 +315,6 @@ fn forceinline long syscall6(long n, long a1, long a2, long a3, long a4, long a5
return ret; return ret;
} }
fn u8 memeq(u8* a, u8* b, u64 size)
{
for (u64 i = 0; i < size; i += 1)
{
if (a[i] != b[i])
{
return 0;
}
}
return 1;
}
enum class SyscallX86_64 : u64 { enum class SyscallX86_64 : u64 {
read = 0, read = 0,
@ -685,40 +687,69 @@ enum class SyscallX86_64 : u64 {
futex_requeue = 456, futex_requeue = 456,
}; };
fn void* syscall_mmap(void* address, size_t length, int protection_flags, int map_flags, int fd, __off_t offset) #endif
fn void* syscall_mmap(void* address, size_t length, int protection_flags, int map_flags, int fd, signed long offset)
{ {
#ifdef __linux__
return (void*) syscall6(static_cast<long>(SyscallX86_64::mmap), (unsigned long)address, length, protection_flags, map_flags, fd, offset); return (void*) syscall6(static_cast<long>(SyscallX86_64::mmap), (unsigned long)address, length, protection_flags, map_flags, fd, offset);
#else
return mmap(address, length, protection_flags, map_flags, fd, offset);
#endif
} }
fn int syscall_mprotect(void *address, size_t length, int protection_flags) fn int syscall_mprotect(void *address, size_t length, int protection_flags)
{ {
#ifdef __linux__
return syscall3(static_cast<long>(SyscallX86_64::mprotect), (unsigned long)address, length, protection_flags); return syscall3(static_cast<long>(SyscallX86_64::mprotect), (unsigned long)address, length, protection_flags);
#else
return mprotect(address, length, protection_flags);
#endif
} }
fn int syscall_open(const char *file_path, int flags, int mode) fn int syscall_open(const char *file_path, int flags, int mode)
{ {
#ifdef __linux__
return syscall3(static_cast<long>(SyscallX86_64::open), (unsigned long)file_path, flags, mode); return syscall3(static_cast<long>(SyscallX86_64::open), (unsigned long)file_path, flags, mode);
#else
return open(file_path, flags, mode);
#endif
} }
fn int syscall_fstat(int fd, struct stat *buffer) fn int syscall_fstat(int fd, struct stat *buffer)
{ {
#ifdef __linux__
return syscall2(static_cast<long>(SyscallX86_64::fstat), fd, (unsigned long)buffer); return syscall2(static_cast<long>(SyscallX86_64::fstat), fd, (unsigned long)buffer);
#else
return fstat(fd, buffer);
#endif
} }
fn ssize_t syscall_read(int fd, void* buffer, size_t bytes) fn ssize_t syscall_read(int fd, void* buffer, size_t bytes)
{ {
#ifdef __linux__
return syscall3(static_cast<long>(SyscallX86_64::read), fd, (unsigned long)buffer, bytes); return syscall3(static_cast<long>(SyscallX86_64::read), fd, (unsigned long)buffer, bytes);
#else
return read(fd, buffer, bytes);
#endif
} }
fn ssize_t syscall_write(int fd, const void *buffer, size_t bytes) fn ssize_t syscall_write(int fd, const void *buffer, size_t bytes)
{ {
#ifdef __linux__
return syscall3(static_cast<long>(SyscallX86_64::write), fd, (unsigned long)buffer, bytes); return syscall3(static_cast<long>(SyscallX86_64::write), fd, (unsigned long)buffer, bytes);
#else
return write(fd, buffer, bytes);
#endif
} }
[[noreturn]] [[gnu::cold]] fn void syscall_exit(int status) [[noreturn]] [[gnu::cold]] fn void syscall_exit(int status)
{ {
#ifdef __linux__
(void)syscall1(231, status); (void)syscall1(231, status);
trap(); #else
_exit(status);
#endif
} }
[[noreturn]] [[gnu::cold]] fn void fail() [[noreturn]] [[gnu::cold]] fn void fail()
@ -3779,7 +3810,11 @@ String test_file_paths[] = {
strlit("tests/simple_variable_declaration/main.nat"), strlit("tests/simple_variable_declaration/main.nat"),
}; };
#ifdef __linux__
extern "C" void entry_point() extern "C" void entry_point()
#else
int main()
#endif
{ {
instance.arena = Arena::init(Arena::default_size, Arena::minimum_granularity, KB(4)); instance.arena = Arena::init(Arena::default_size, Arena::minimum_granularity, KB(4));

View File

@ -1,27 +1,23 @@
#!/bin/bash #!/bin/bash
NEST_BUILD_DIR=build
NEST_EXE_NAME=nest function compile()
set -ex {
mkdir -p $NEST_BUILD_DIR build_dir=$1
time clang++ \ exe_name=$2
-o $NEST_BUILD_DIR/$NEST_EXE_NAME \ debug_info=$3
bootstrap/main.cpp \ optimizations=$4
bootstrap/entry.S \
`# -Oz` \ mkdir -p $build_dir
`# -march=native` \
`# -Wl,-strip-all` \ compile_command="time clang++ -o $build_dir/$exe_name $debug_info $optimizations -std=gnu++20 -Wall -Wextra -Wpedantic -Wno-nested-anon-types -pedantic -fno-exceptions -fno-stack-protector -ferror-limit=1 -MJ $build_dir/compile_commands.json"
-g \
-std=gnu++23 \ case "$OSTYPE" in
-Wall \ darwin*) ;;
-Wextra \ linux*) compile_command="$compile_command -ffreestanding -nostdlib -static bootstrap/entry.S" ;;
-Wpedantic \ *) echo "unknown: $OSTYPE" ;;
-Wno-nested-anon-types \ esac
-pedantic \
-ffreestanding \ compile_command="$compile_command bootstrap/main.cpp"
-nostdlib \ echo $compile_command
-static \ eval $compile_command
-fno-exceptions \ }
-fno-stack-protector \
-ferror-limit=1 \
`#-ftime-report` \
-MJ $NEST_BUILD_DIR/compile_commands.json

View File

@ -1,4 +1,16 @@
#!/bin/bash #!/bin/bash
set -ex
set -e
source ./compile.sh source ./compile.sh
gf2 -ex r $NEST_BUILD_DIR/$NEST_EXE_NAME build_dir="build"
exe_name="nest"
exe_path=$build_dir/$exe_name
compile $build_dir $exe_name "-g" "";
case "$OSTYPE" in
darwin*) lldb $exe_path ;;
linux*) gf2 -ex r $exe_path ;;
*) echo "unknown: $OSTYPE" ;;
esac

View File

@ -1,4 +1,6 @@
#!/bin/bash #!/bin/bash
set -ex set -ex
source ./compile.sh source ./compile.sh
compile "build" "nest" "-g" "";
build/nest build/nest