-
Notifications
You must be signed in to change notification settings - Fork 42
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
WIP: Initial changes to support macOS build #35
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[submodule "Nim"] | ||
path = Nim | ||
url = https://github.com/arnetheduck/Nim.git | ||
url = https://github.com/gushromp/Nim.git | ||
branch = nlvm |
+26 −35 | lib/posix/posix_macos_amd64.nim | |
+17 −4 | lib/pure/concurrency/cpuinfo.nim | |
+5 −5 | lib/pure/os.nim | |
+9 −0 | lib/system/ansi_c.nim | |
+3 −1 | lib/system/io.nim |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,42 +3,75 @@ | |
# See the LICENSE file for license info (doh!) | ||
|
||
import strutils | ||
import strformat | ||
import os | ||
|
||
static: | ||
if not (defined(linux) or defined(macosx)): | ||
echo "Unsupported platform. Exiting." | ||
quit(-1) | ||
|
||
const | ||
LLVMLib = "libLLVM-14.so" | ||
LLVMRoot = "../ext/llvm-14.0.0.src/" | ||
LLDRoot = "../ext/lld-14.0.0.src/" | ||
Root = currentSourcePath.parentDir().parentDir() | ||
LLVMVersion* = "14.0.0" | ||
LLVMRoot = fmt"{Root}/ext/llvm-{LLVMVersion}.src" | ||
LLDRoot = fmt"{Root}/ext/lld-{LLVMVersion}.src" | ||
|
||
{.passL: "-llldELF" .} | ||
{.passL: "-llldWasm" .} | ||
{.passL: "-llldMinGW" .} | ||
{.passL: "-llldCommon" .} | ||
{.passL: "-llldMachO" .} | ||
{.passL: "-lz" .} | ||
when defined(macosx): | ||
{.passL: "-lxar" .} | ||
|
||
when defined(staticLLVM): | ||
const | ||
LLVMOut = LLVMRoot & "sta/" | ||
LLVMOut = fmt"{LLVMRoot}/sta" | ||
|
||
{.passL: gorge(fmt"{LLVMRoot}/sta/bin/llvm-config --libs all").} | ||
|
||
{.passL: gorge(LLVMRoot & "sta/bin/llvm-config --libs all").} | ||
when defined(macosx): | ||
const SDKRoot = gorge("xcrun --sdk macosx --show-sdk-path") | ||
{.passC: fmt"-isysroot{SDKRoot}".} | ||
{.passL: fmt"-Wl,-syslibroot,{SDKRoot}".} | ||
|
||
else: | ||
const | ||
LLVMOut = LLVMRoot & "sha/" | ||
LLVMOut = fmt"{LLVMRoot}/sha" | ||
|
||
when defined(macosx): | ||
{.passL: "-lLLVM".} | ||
{.passL: fmt"-Wl,-rpath,@loader_path/../ext/llvm-{LLVMVersion}.src/sha/lib".} | ||
|
||
elif defined(linux): | ||
{.passL: "-lLLVM-14".} | ||
{.passL: fmt"-Wl,'-rpath=$ORIGIN/../ext/llvm-{LLVMVersion}.src/sha/lib'".} | ||
|
||
|
||
{.passL: "-lLLVM-14".} | ||
{.passL: "-Wl,'-rpath=$ORIGIN/" & LLVMOut & "lib/'".} | ||
{.passC: fmt"-I{LLVMRoot}/include".} | ||
{.passC: fmt"-I{LLVMOut}/include".} | ||
|
||
{.passC: "-I" & LLVMRoot & "include".} | ||
{.passC: "-I" & LLVMOut & "include".} | ||
{.passC: fmt"-I{LLDRoot}/include".} | ||
|
||
{.passC: "-I" & LLDRoot & "include".} | ||
when defined(linux): | ||
{.passL: "-Wl,--as-needed".} | ||
else: | ||
{.passL: "-Wl".} | ||
|
||
{.passL: gorge(fmt"{LLVMOut}/bin/llvm-config --ldflags").} | ||
{.passL: gorge(fmt"{LLVMOut}/bin/llvm-config --system-libs").} | ||
|
||
{.passL: "-Wl,--as-needed".} | ||
{.passL: gorge(LLVMOut & "bin/llvm-config --ldflags").} | ||
{.passL: gorge(LLVMOut & "bin/llvm-config --system-libs").} | ||
{.compile("wrapper.cc", "-std=c++14").} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and with a small upstream fix, this is not needed either: 4355022 |
||
|
||
{.compile: "wrapper.cc".} | ||
when defined(linux): | ||
const | ||
LLVMLib = "libLLVM-14.so" | ||
elif defined(macosx): | ||
const | ||
LLVMLib = "libLLVM.dylib" | ||
LLDBinary* = fmt"{LLVMOut}/bin/ld64.lld" | ||
|
||
# Includes and helpers for generated code | ||
type | ||
|
@@ -264,6 +297,18 @@ proc nimLLDLinkElf*(args: openArray[string]): string = | |
result = strip($tmp) | ||
disposeMessage(tmp) | ||
|
||
proc nimLLDLinkMachO*( | ||
argv: cstringArray, argc: cint): cstring {.importc: "LLVMNimLLDLinkMachO".} | ||
|
||
proc nimLLDLinkMachO*(args: openArray[string]): string = | ||
let argv = allocCStringArray(args) | ||
defer: deallocCStringArray(argv) | ||
|
||
let tmp = nimLLDLinkMachO(argv, args.len.cint) | ||
if not tmp.isNil: | ||
result = strip($tmp) | ||
disposeMessage(tmp) | ||
|
||
proc nimLLDLinkWasm*( | ||
argv: cstringArray, argc: cint): cstring {.importc: "LLVMNimLLDLinkWasm".} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,20 @@ | |
# Build llvm, as used in the Makefile | ||
# A bit broken because it doesn't track cmake options and deps correctly | ||
|
||
OS="`uname`" | ||
case $OS in | ||
'Linux') | ||
ADDITIONAL_CMAKE_ARGS="-DLLVM_USE_LINKER=gold" | ||
;; | ||
'Darwin') | ||
ADDITIONAL_CMAKE_ARGS="" | ||
;; | ||
*) | ||
echo "Unsupported OS: $OS" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
[ $# -gt 4 ] || { | ||
echo "$0 major minor patch output_dir cmake_options*" | ||
exit 1 | ||
|
@@ -39,7 +53,7 @@ LLD_ROOT=lld-$VER2.src | |
[ -d $LLVM_ROOT/projects/lld ] || { | ||
rm -rf $LLVM_ROOT/projects/lld | ||
cd $LLVM_ROOT/projects | ||
ln -sfr ../../$LLD_ROOT lld | ||
ln -sf ../../$LLD_ROOT lld | ||
cd ../.. | ||
} | ||
|
||
|
@@ -49,7 +63,7 @@ LLD_ROOT=lld-$VER2.src | |
|
||
[ -f libunwind-$VER2/CMakeLists.txt ] || { | ||
tar xf libunwind-$VER2.src.tar.xz | ||
cp -ar libunwind-$VER2.src/include/mach-o $LLD_ROOT/include | ||
cp -a libunwind-$VER2.src/include/mach-o $LLD_ROOT/include | ||
} | ||
|
||
cd $LLVM_ROOT | ||
|
@@ -58,6 +72,6 @@ mkdir -p $TGT | |
cd $TGT | ||
|
||
shift 4 | ||
cmake -GNinja -DLLVM_USE_LINKER=gold LLVM_INCLUDE_BENCHMARKS=OFF "$@" .. | ||
cmake -GNinja "$@" .. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should continue to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah sorry I made |
||
|
||
ninja |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no need to quit in general, even if there's no explicit support for a platform - ie if it breaks, it'll break but maybe it won't