-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nim added - host must be linux, no nimble
- Loading branch information
Showing
5 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
if [ "$TARGET_OS" = "linux" ] && [ "$TARGET_ARCH" = "x86_64" ] | ||
then | ||
src=$(fetch_untar \ | ||
"https://nim-lang.org/download/nim-2.0.2-linux_x64.tar.xz" \ | ||
"nim.tar.xz" \ | ||
"047dde8ff40b18628ac1188baa9ca992d05f1f45c5121d1d07a76224f06e1551") | ||
else | ||
>&2 echo "unsupported os+arch for nim" | ||
fi | ||
|
||
cd "$BUILD_OUT" | ||
mkdir bin | ||
ln -s $src/bin/nim bin | ||
cp "$BUILD_PKG"/nimc bin | ||
cp "$BUILD_PKG"/nimcc bin | ||
cp "$BUILD_PKG"/nimi bin | ||
ln -s $(which ar) bin/llvm-ar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env sh | ||
exec nim c \ | ||
--cc:clang \ | ||
--os:$(nimi os $TARGET_OS) \ | ||
--cpu:$(nimi arch $TARGET_ARCH) \ | ||
--clang.exe="nimcc" \ | ||
--clang.linkerexe="nimcc" \ | ||
--verbosity:0 \ | ||
$(nimi opt $OPT_ZIG) \ | ||
"$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env sh | ||
exec zig cc -target $TARGET -O$OPT "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env sh | ||
|
||
nimos() { | ||
os=$1 | ||
if [ "$os" = "linux" ] | ||
then | ||
echo "Linux" | ||
elif [ "$os" = "macos" ] | ||
then | ||
echo "MacOSX" | ||
elif [ "$os" = "windows" ] | ||
then | ||
echo "Windows" | ||
else | ||
>&2 echo "unrecognized os for nim $os" | ||
exit 1 | ||
fi | ||
} | ||
|
||
nimarch() { | ||
arch=$1 | ||
if [ "$arch" = "x86_64" ] | ||
then | ||
echo "amd64" | ||
elif [ "$arch" = "aarch64" ] | ||
then | ||
echo "arm64" | ||
else | ||
>&2 echo "unrecognized arch for nim $arch" | ||
exit 1 | ||
fi | ||
} | ||
|
||
nimopt() { | ||
opt=$1 | ||
case $opt in | ||
Debug) | ||
;; | ||
ReleaseSmall) | ||
echo "-d:release --opt:size" | ||
;; | ||
Release*) | ||
echo "-d:release" | ||
;; | ||
*) | ||
>&2 echo "unrecognized nimi opt mode $opt" | ||
;; | ||
esac | ||
} | ||
|
||
case $1 in | ||
os) | ||
nimos $2 | ||
;; | ||
arch) | ||
nimarch $2 | ||
;; | ||
opt) | ||
nimopt $2 | ||
;; | ||
*) | ||
>&2 echo "unrecognized nimi command $1" | ||
exit 1 | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
needtool nim | ||
export PATH="$BUILD_TOOLS/nim/bin:$PATH" | ||
|
||
# Binary | ||
cat <<EOF > hello.nim | ||
echo "Hello World" | ||
EOF | ||
nimc hello.nim | ||
|
||
# Static library | ||
cat <<EOF > hellofn.nim | ||
proc hello(name:cstring) {.exportc.} = | ||
echo name | ||
EOF | ||
nimc --app:staticlib hellofn.nim | ||
|
||
cat <<EOF > hello2.c | ||
extern void hello(char*); | ||
int main(int argc, char** argv) { | ||
hello(argv[1]); | ||
} | ||
EOF | ||
cc -target $TARGET -O$OPT \ | ||
-o $(zigi exe hello2) \ | ||
hello2.c \ | ||
$(zigi lib hellofn) \ | ||
-lc | ||
|
||
cd "$BUILD_OUT" | ||
mkdir bin lib | ||
cp "$HOME"/$(zigi exe hello) bin | ||
cp "$HOME"/$(zigi exe hello2) bin | ||
cp "$HOME"/$(zigi lib hellofn) lib |