Showing with 33 additions and 18 deletions.
  1. +1 −1 compiler/installer.ini
  2. +6 −1 config/nim.cfg
  3. +1 −1 lib/nimbase.h
  4. +10 −8 lib/pure/os.nim
  5. +8 −2 tools/niminst/buildsh.tmpl
  6. +7 −5 tools/niminst/makefile.tmpl
2 changes: 1 addition & 1 deletion compiler/installer.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Version: "$version"
Platforms: """
windows: i386;amd64
linux: i386;amd64;powerpc64;arm;sparc;mips;mipsel;mips64;mips64el;powerpc;powerpc64el;arm64;riscv64
macosx: i386;amd64;powerpc64
macosx: i386;amd64;powerpc;powerpc64
solaris: i386;amd64;sparc;sparc64
freebsd: i386;amd64
netbsd: i386;amd64
Expand Down
7 changes: 6 additions & 1 deletion config/nim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ path="$lib/pure"
@end

@if macosx or freebsd:
cc = clang
@if macosx and powerpc:
# no clang and missing posix_spawn
define:useFork
@else:
cc = clang
@end
tlsEmulation:on
gcc.options.always = "-w"
gcc.cpp.options.always = "-w -fpermissive"
Expand Down
2 changes: 1 addition & 1 deletion lib/nimbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ typedef int Nim_and_C_compiler_disagree_on_target_architecture[sizeof(NI) == siz
# include <sys/types.h>
# include <types/vxWind.h>
# include <tool/gnu/toolMacros.h>
#elif defined(__FreeBSD__)
#elif defined(__FreeBSD__) || defined(__APPLE__)
# include <sys/types.h>
#endif

Expand Down
18 changes: 10 additions & 8 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ proc setCurrentDir*(newDir: string) {.inline, tags: [].} =
else:
if chdir(newDir) != 0'i32: raiseOSError(osLastError())

when defined(posix):
var
pathMax {.importc: "PATH_MAX", header: "<stdlib.h>".}: cint

proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
tags: [ReadDirEffect].} =
## Returns the full (`absolute`:idx:) path of the file `filename`,
Expand Down Expand Up @@ -329,14 +333,12 @@ proc expandFilename*(filename: string): string {.rtl, extern: "nos$1",
setLen(result, L)
break
else:
# according to Posix we don't need to allocate space for result pathname.
# But we need to free return value with free(3).
var r = realpath(filename, nil)
if r.isNil:
raiseOSError(osLastError())
else:
result = $r
c_free(cast[pointer](r))
# realpath needs to take an allocated buffer according to POSIX-2004.
# dynamic allocation by passing NULL is only available since POSIX-2017
result = newString(pathMax)
var r = realpath(filename, result)
if r.isNil: raiseOSError(osLastError())
setLen(result, c_strlen(result))

when defined(Windows):
proc openHandle(path: string, followSymlink=true, writeAccess=false): Handle =
Expand Down
10 changes: 8 additions & 2 deletions tools/niminst/buildsh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ case $uos in
;;
*darwin* )
myos="macosx"
CC="clang"
LINKER="clang"
case $HOSTTYPE in
powerpc)
ucpu="powerpc"
;;
*)
CC="clang"
LINKER="clang"
esac
LINK_FLAGS="$LINK_FLAGS -ldl -lm"
if [ "$HOSTTYPE" = "x86_64" ] ; then
ucpu="amd64"
Expand Down
12 changes: 7 additions & 5 deletions tools/niminst/makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ ifeq ($(uos),netbsd)
endif
ifeq ($(uos),darwin)
myos = macosx
CC = clang
LD = clang
LDFLAGS += -ldl -lm
ifeq ($(HOSTTYPE),x86_64)
ucpu = amd64
ifeq ($(ucpu),power macintosh)
ucpu = powerpc
LD = gcc
else
CC = clang
LD = clang
endif
LDFLAGS += -ldl -lm
endif
ifeq ($(uos),aix)
myos = aix
Expand Down