Skip to content

Commit

Permalink
Update and extend build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
524D committed Jun 4, 2024
1 parent 28d06e3 commit 87f75db
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
5 changes: 2 additions & 3 deletions build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ mkdir -p $TARGET_DIR
# Obtain version number from git
VERSION=$(git describe --abbrev --dirty --always --tags)
VERSION=${VERSION#"v"}
# build flags are set to creat a binairy reproducable, fully statically linked executable that includes the Git version number
# build flags are set to create a binairy reproducable, fully statically linked executable that includes the Git version number
# -trimpath: don't inlude full source code path names in the executable. Needed to produce binairy reproducable output.
# -ldflags:
# -extldflags \"-static\" : statically link cgo code. This flag is not needed in the current verion and will be removed.
# -buildid= : clear the buildid, needed to produce binairy reproducable output
# -X main.progVersion=${VERSION} : include Git version info (from enviroment variable ${VERSION}).
# This will probably be replaced by using function debug.ReadBuildInfo() from package "runtime/debug" in the future,
# so that we don't need this build script anymore

echo 'Building mzrecal for Linux/amd64'
GOOS=linux GOARCH=amd64 go build -trimpath -a -ldflags "-extldflags \"-static\" -buildid= -X main.progVersion=${VERSION}" -o $TARGET_DIR/mzrecal
GOOS=linux GOARCH=amd64 go build -trimpath -a -ldflags "-buildid= -X main.progVersion=${VERSION}" -o $TARGET_DIR/mzrecal

# Create Docker image
cp Dockerfile $TARGET_DIR
Expand Down
33 changes: 30 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,41 @@ VERSION=${VERSION#"v"}
# build flags are set to creat a binairy reproducable, fully statically linked executable that includes the Git version number
# -trimpath: don't inlude full source code path names in the executable. Needed to produce binairy reproducable output.
# -ldflags:
# -extldflags \"-static\" : statically link cgo code. This flag is not needed in the current verion and will be removed.
# -buildid= : clear the buildid, needed to produce binairy reproducable output
# -X main.progVersion=${VERSION} : include Git version info (from enviroment variable ${VERSION}).
# This will probably be replaced by using function debug.ReadBuildInfo() from package "runtime/debug" in the future,
# so that we don't need this build script anymore

echo 'Building mzrecal for Linux/amd64'
GOOS=linux GOARCH=amd64 go build -trimpath -a -ldflags "-extldflags \"-static\" -buildid= -X main.progVersion=${VERSION}" -o $TARGET_DIR/mzrecal
GOOS=linux GOARCH=amd64 go build -trimpath -a -ldflags "-buildid= -X main.progVersion=${VERSION}" -o $TARGET_DIR/mzrecal

echo 'Building mzrecal for Windows/amd64'
GOOS=windows GOARCH=amd64 go build -trimpath -a -ldflags "-extldflags \"-static\" -buildid= -X main.progVersion=${VERSION}" -o $TARGET_DIR/mzrecal.exe
GOOS=windows GOARCH=amd64 go build -trimpath -a -ldflags "-buildid= -X main.progVersion=${VERSION}" -o $TARGET_DIR/mzrecal.exe

# Generate zip/tar.gz files
# Create a temporary directory
TMPDIR=$(mktemp -d)
# Copy the executable to the temporary directory
cp $TARGET_DIR/mzrecal.exe $TMPDIR
mkdir $TMPDIR/mzrecal
cp $TARGET_DIR/mzrecal $TMPDIR/mzrecal/

cd $TMPDIR
# Check if running on Windows
if [ -n "$WINDIR" ]; then
# Running on Windows
"/c/Program Files/7-Zip/7z.exe" a mzrecal-${VERSION}_windows-64bit.zip mzrecal.exe
"/c/Program Files/7-Zip/7z.exe" a mzrecal-${VERSION}_linux-64bit.tar mzrecal
"/c/Program Files/7-Zip/7z.exe" a mzrecal-${VERSION}_linux-64bit.tar.gz mzrecal-${VERSION}_linux-64bit.tar
else
zip mzrecal-${VERSION}_windows-64bit.zip mzrecal.exe
tar -czf mzrecal-${VERSION}_linux-64bit.tar.gz mzrecal
fi

# Copy the zip/tar.gz files to the target directory
cp mzrecal-${VERSION}_windows-64bit.zip $TARGET_DIR
cp mzrecal-${VERSION}_linux-64bit.tar.gz $TARGET_DIR

# Remove the temporary directory
cd ~
rm -rf $TMPDIR

0 comments on commit 87f75db

Please sign in to comment.