Skip to content

Commit

Permalink
nim added - host must be linux, no nimble
Browse files Browse the repository at this point in the history
  • Loading branch information
rsepassi committed Mar 26, 2024
1 parent cca6225 commit c15c9a3
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/nim/build.sh
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

10 changes: 10 additions & 0 deletions pkg/nim/nimc
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) \
"$@"
2 changes: 2 additions & 0 deletions pkg/nim/nimcc
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 "$@"
65 changes: 65 additions & 0 deletions pkg/nim/nimi
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
34 changes: 34 additions & 0 deletions pkg/nimhello/build.sh
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

0 comments on commit c15c9a3

Please sign in to comment.