Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS support #382

Merged
merged 46 commits into from
Dec 4, 2023
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ab7d188
Run github actions tests on macos
Akuli Apr 3, 2023
56a3edb
brew search llvm
Akuli Apr 3, 2023
1d8422c
Disable unrelated stuff for now
Akuli Apr 3, 2023
cee1061
lets try with installing the llvm
Akuli Apr 3, 2023
a40e90c
Lets try adding to path
Akuli Apr 3, 2023
ffc3e15
Lets try passing llvm-config path a bit differently
Akuli Apr 3, 2023
9820b10
Sanity check LLVM version in Makefile
Akuli Apr 3, 2023
3ce687b
use bash
Akuli Apr 3, 2023
d42aed0
Clean up ls commands. Try to enable compare-compilers
Akuli Apr 3, 2023
cdd73a9
Lets just use LLVM 13
Akuli Apr 3, 2023
2c06d74
Lets avoid mapfile? wHAT IS THIS bash version anyway
Akuli Apr 3, 2023
e8eaf5b
Print out bash version
Akuli Apr 3, 2023
2317076
asd
Akuli Apr 3, 2023
ac1760b
Lets try to install bash
Akuli Apr 4, 2023
b1fa1c0
Try to use the newer bash
Akuli Apr 4, 2023
109f1fb
Try install gnu diff
Akuli Apr 4, 2023
6c9ca19
cleanup time
Akuli Apr 4, 2023
596197a
Lets try _NSGetExecutablePath
Akuli Apr 4, 2023
fd225f8
fixening
Akuli Apr 4, 2023
26b4bfa
Lets try something
Akuli Apr 4, 2023
ce50c63
Lets find all da names
Akuli Apr 4, 2023
287ef77
Also find out errno while we're at it
Akuli Apr 4, 2023
e2f4005
create _macos_startup.jou with copy/pasta spaghetti bolognese carbonara
Akuli Apr 4, 2023
07f6e93
bruh
Akuli Apr 4, 2023
f637fc9
ez fix
Akuli Apr 4, 2023
2517606
bruh
Akuli Apr 4, 2023
0db25cc
env
Akuli Apr 5, 2023
bf767e7
Merge remote-tracking branch 'origin/main' into mac-ci
Akuli Dec 3, 2023
f77a686
fix is_macos maybe
Akuli Dec 4, 2023
64b9acd
try thing
Akuli Dec 4, 2023
10cd460
trying lots of stuff
Akuli Dec 4, 2023
3733039
bruh
Akuli Dec 4, 2023
9665c1c
stufsg
Akuli Dec 4, 2023
e92f714
one more?
Akuli Dec 4, 2023
5c9a9b0
MOAR
Akuli Dec 4, 2023
75a6311
apply startup hack
Akuli Dec 4, 2023
9ef78ec
lets try tests!!!
Akuli Dec 4, 2023
f5ef50e
u happy now
Akuli Dec 4, 2023
2d7ebdc
final version if lucky?
Akuli Dec 4, 2023
bf5ad74
last fix?
Akuli Dec 4, 2023
10ff4df
./compare_compilers.sh --fix
Akuli Dec 4, 2023
c8d9474
tab
Akuli Dec 4, 2023
9bd3958
hax go brr
Akuli Dec 4, 2023
55ea98e
macos instructions
Akuli Dec 4, 2023
b2158bd
Apply suggestions from code review
Akuli Dec 4, 2023
8611e35
Update README.md
Akuli Dec 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
hax go brr
Akuli committed Dec 4, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 9bd3958d07bd7fb8f3aa6dca66a0b7b1cdaceab8
70 changes: 61 additions & 9 deletions self_hosted/paths.jou
Original file line number Diff line number Diff line change
@@ -9,31 +9,83 @@ declare _mkdir(path: byte*) -> int # windows
declare mkdir(path: byte*, mode: int) -> int # posix
declare dirname(path: byte*) -> byte*
declare stat(path: byte*, buf: byte[1000]*) -> int # lol
declare popen(command: byte*, type: byte*) -> FILE*
declare pclose(stream: FILE*) -> int
declare _NSGetExecutablePath(buf: byte*, bufsize: int*) -> int


def is_windows() -> bool:
# TODO: this is just weird...
return getenv("OS") != NULL and strstr(getenv("OS"), "Windows") != NULL

# Return a path to the currently running program. Return value must be free()d.
def find_current_executable() -> byte*:
# https://stackoverflow.com/a/3466183
def is_macos() -> bool:
if is_windows():
return False

uname = popen("uname", "r")
if uname == NULL:
return False

output: byte[100]
memset(&output, 0, sizeof(output))
fgets(output, sizeof(output) as int, uname)

pclose(uname)
return starts_with(output, "Darwin")


def _find_current_executable_windows() -> byte*:
buf = NULL
for size = 2L; True; size *= 2:
buf = realloc(buf, size)
memset(buf, 0, size)
ret = GetModuleFileNameA(NULL, buf, size as int)
if ret <= 0:
return NULL # error --> give up
if ret < size:
# buffer is big enough, it fits
return buf

if is_windows():
ret: long = GetModuleFileNameA(NULL, buf, size as int)
else:
ret = readlink("/proc/self/exe", buf, size)
def _find_current_executable_macos() -> byte*:
n = 1
result: byte* = malloc(n)
ret = _NSGetExecutablePath(result, &n) # sets n to desired size
assert ret < 0 # didn't fit
result = realloc(result, n)
ret = _NSGetExecutablePath(result, &n)
assert ret == 0
return result

def _find_current_executable_linux() -> byte*:
buf = NULL
for size = 2L; True; size *= 2:
buf = realloc(buf, size)
memset(buf, 0, size)
ret = readlink("/proc/self/exe", buf, size)
if ret <= 0:
# TODO: include os error message (GetLastError / errno)
fprintf(stderr, "error: cannot locate currently running executable, needed for finding the Jou standard library\n")
exit(1)
return NULL
if ret < size:
# buffer is big enough, it fits
return buf


def find_current_executable() -> byte*:
if is_windows():
result = _find_current_executable_windows()
elif is_macos():
result = _find_current_executable_macos()
else:
result = _find_current_executable_linux()

if result == NULL:
# TODO: include os error message (GetLastError / errno)
fprintf(stderr, "error: cannot locate currently running executable, needed for finding the Jou standard library\n")
exit(1)

return result


def find_installation_directory() -> byte*:
exe = find_current_executable()
result = strdup(dirname(exe))
6 changes: 4 additions & 2 deletions src/codegen.c
Original file line number Diff line number Diff line change
@@ -190,9 +190,11 @@ static LLVMValueRef codegen_function_or_method_decl(const struct State *st, cons
// make it a definition instead of a declaration so that there are no linker errors.
// Ideally it would be possible to compile some parts of Jou code only for a specific platform.
#ifdef _WIN32
const char *doesnt_exist[] = { "readlink", "mkdir", "popen", "pclose" };
#else
const char *doesnt_exist[] = { "readlink", "mkdir", "popen", "pclose", "_NSGetExecutablePath" };
#elif defined(__APPLE__)
const char *doesnt_exist[] = { "GetModuleFileNameA", "_mkdir" };
#else
const char *doesnt_exist[] = { "GetModuleFileNameA", "_mkdir", "_NSGetExecutablePath" };
#endif
for (unsigned i = 0; i < sizeof doesnt_exist / sizeof doesnt_exist[0]; i++) {
if (!strcmp(fullname, doesnt_exist[i])) {