From 3cb0b47e4d506c34ee00db57fa03a16c7987100e Mon Sep 17 00:00:00 2001 From: Rath Pascal Date: Sun, 19 Jan 2025 14:41:21 +0100 Subject: [PATCH] move build-scripts --- .github/workflows/test.yml | 4 +- README.md | 2 +- src/lib/build.sh => scripts/build_cgo.sh | 2 +- src/cmd/build.sh => scripts/build_cli.sh | 2 +- scripts/build_release.sh | 64 ++++++++++++++++++++++++ src/build_release.sh | 26 ---------- 6 files changed, 69 insertions(+), 31 deletions(-) rename src/lib/build.sh => scripts/build_cgo.sh (81%) rename src/cmd/build.sh => scripts/build_cli.sh (78%) create mode 100644 scripts/build_release.sh delete mode 100644 src/build_release.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c79037..4b3a64a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,8 +49,8 @@ jobs: - name: Building Go Binaries run: | - bash src/cmd/build.sh - bash src/lib/build.sh + bash scripts/build_cli.sh + bash scripts/build_cgo.sh - name: Running Unit Tests run: | diff --git a/README.md b/README.md index 00e75fe..25dc59c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ You first need to either [download](https://github.com/O-X-L/opensimplex/release 1. [Golang download/install](https://go.dev/doc/install) -2. Build them: `bash src/cmd/build.sh` and/or `bash src/lib/build.sh` +2. Build them: `bash scripts/build_cli.sh` and/or `bash scripts/build_cgo.sh` ---- diff --git a/src/lib/build.sh b/scripts/build_cgo.sh similarity index 81% rename from src/lib/build.sh rename to scripts/build_cgo.sh index c44d649..b2a7e58 100644 --- a/src/lib/build.sh +++ b/scripts/build_cgo.sh @@ -2,7 +2,7 @@ set -euo pipefail -cd "$(dirname "$0")" +cd "$(dirname "$0")/../src/lib" PATH_OUT="$(pwd)/../.." diff --git a/src/cmd/build.sh b/scripts/build_cli.sh similarity index 78% rename from src/cmd/build.sh rename to scripts/build_cli.sh index 1f826fd..1e30784 100644 --- a/src/cmd/build.sh +++ b/scripts/build_cli.sh @@ -2,7 +2,7 @@ set -euo pipefail -cd "$(dirname "$0")" +cd "$(dirname "$0")../src/cmd" PATH_OUT="$(pwd)/../.." diff --git a/scripts/build_release.sh b/scripts/build_release.sh new file mode 100644 index 0000000..32f21b9 --- /dev/null +++ b/scripts/build_release.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +set -uo pipefail + +cd "$(dirname "$0")/../src" +PATH_SRC="$(pwd)" +PATH_BUILD="${PATH_SRC}/../build" +mkdir -p "$PATH_BUILD" +rm -f "${PATH_BUILD}/"* + +function compile() { + os="$1" arch="$2" + echo "COMPILING BINARIES FOR ${os}-${arch}" + + cd "$PATH_SRC" + name_out_lib="noise_cgo_${os}_${arch}" + path_out_lib="${PATH_BUILD}/${name_out_lib}" + GOOS="$os" GOARCH="$arch" go build -buildmode=c-shared -o "${path_out_lib}.so" "${PATH_SRC}/lib/noise_cgo.go" + + name_out_cli="noise_cli_${os}_${arch}" + GOOS="$os" GOARCH="$arch" go build -o "${PATH_BUILD}/${name_out_cli}" "${PATH_SRC}/cmd/noise_cli.go" + GOOS="$os" GOARCH="$arch" CGO_ENABLED=0 go build -o "${PATH_BUILD}/${name_out_cli}-CGO0" "${PATH_SRC}/cmd/noise_cli.go" + + cd "$PATH_BUILD" + if [[ "$os" == "windows" ]] + then + if [ -f "${name_out_lib}.so" ] + then + zip "${name_out_lib}.zip" "${name_out_lib}"* + fi + zip "${name_out_cli}.zip" "${name_out_cli}" + zip "${name_out_cli}-CGO0.zip" "${name_out_cli}-CGO0" + else + if [ -f "${name_out_lib}.so" ] + then + tar -czf "${name_out_lib}.tar.gz" "${name_out_lib}"* + fi + tar -czf "${name_out_cli}.tar.gz" "${name_out_cli}" + tar -czf "${name_out_cli}-CGO0.tar.gz" "${name_out_cli}-CGO0" + fi +} + +compile "linux" "amd64" + +# untested: +compile "linux" "386" +compile "linux" "arm" +compile "linux" "arm64" + +compile "freebsd" "386" +compile "freebsd" "amd64" +compile "freebsd" "arm" + +compile "openbsd" "386" +compile "openbsd" "amd64" +compile "openbsd" "arm" + +compile "darwin" "amd64" +compile "darwin" "arm64" + +compile "windows" "386" +compile "windows" "amd64" + +ls -l "$PATH_BUILD" diff --git a/src/build_release.sh b/src/build_release.sh deleted file mode 100644 index 8f88dca..0000000 --- a/src/build_release.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -cd "$(dirname "$0")" -PATH_SRC="$(pwd)" -PATH_BUILD="${PATH_SRC}/../build" -mkdir -p "$PATH_BUILD" -rm -f "${PATH_BUILD}/"* - -echo "### BUILDING CGO LIB ###" -NAME_OUT_LIB="noise_cgo_debian_amd64" -PATH_OUT_LIB="${PATH_BUILD}/${NAME_OUT_LIB}" -go build -buildmode=c-shared -o "${PATH_OUT_LIB}.so" "${PATH_SRC}/lib/noise_cgo.go" - - -echo "### BUILDING CLI ###" -NAME_OUT_CLI="noise_cli_linux_amd64" -go build -o "${PATH_BUILD}/${NAME_OUT_CLI}" "${PATH_SRC}/cmd/noise_cli.go" - -echo "### CREATING ARCHIVES ###" -cd "$PATH_BUILD" -zip "${NAME_OUT_LIB}.zip" "$NAME_OUT_LIB"* -zip "${NAME_OUT_CLI}.zip" "$NAME_OUT_CLI" - -ls -l "$PATH_BUILD"