index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2020-10-15 9:19:12.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2020-10-15 9:19:12.0 +00:00:00
commit
6d3dc45b6b97ddafde7435c2111b9af98f8ae492 [patch]
tree
4f545b567187af7ab15560f0059374e95698edf3
parent
dd20c3e9237bbc8b5607157c30af026ddc3b8406
download
6d3dc45b6b97ddafde7435c2111b9af98f8ae492.tar.gz

refactor: shrink darwin binary size



Diff

 Makefile | 41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index 26a580b..ad9c04b 100644
--- a/Makefile
+++ b/Makefile
@@ -55,7 +55,10 @@ linux:
			cargo build --release --target $(PKG_TARGET) && \
			du -sh ./target/$(PKG_TARGET)/release/$(PKG_NAME) && \
			mkdir -p release && \
			cp -rf ./target/$(PKG_TARGET)/release/$(PKG_NAME) release/$(PKG_NAME)-linux"
			cp -rf ./target/$(PKG_TARGET)/release/$(PKG_NAME) release/$(PKG_NAME)-linux && \
			echo \"Shrinking Linux binary file...\" && \
			strip release/$(PKG_NAME)-linux && \
			du -sh ./release/$(PKG_NAME)-linux"
.PHONY: linux

darwin:
@@ -74,7 +77,10 @@ darwin:
			cargo build --release --target $(PKG_TARGET_DARWIN) && \
			du -sh ./target/$(PKG_TARGET_DARWIN)/release/$(PKG_NAME) && \
			mkdir -p release && \
			cp -rf ./target/$(PKG_TARGET_DARWIN)/release/$(PKG_NAME) release/$(PKG_NAME)-darwin"
			cp -rf ./target/$(PKG_TARGET_DARWIN)/release/$(PKG_NAME) release/$(PKG_NAME)-darwin && \
			echo \"Shrinking Darwin binary file...\" && \
			x86_64-apple-darwin15-strip release/$(PKG_NAME)-darwin && \
			du -sh ./release/$(PKG_NAME)-darwin"
.PHONY: darwin

#######################################
@@ -135,16 +141,23 @@ define build_release_shrink =
	mkdir -p $(PKG_TMP_BIN_PATH_DARWIN)
	cp -rf ./target/$(PKG_TARGET_DARWIN)/release/$(PKG_NAME) $(PKG_TMP_BIN_PATH_DARWIN)

	# Linux only
	echo "Performing binary shrinking for $(PKG_TARGET) release..."
	# Linux
	echo "Performing Linux/Darwin binaries shrinking..."
	echo "Size before:"
	du -sh $(PKG_TMP_BIN_PATH)/$(PKG_NAME)
	du -sh $(PKG_TMP_BIN_PATH)/.

	# Shrink binaries in place (tmp dir)
	strip $(PKG_TMP_BIN_PATH)/$(PKG_NAME)
	x86_64-apple-darwin15-strip $(PKG_TMP_BIN_PATH)/$(PKG_RELEASE_NAME_DARWIN)

	echo "Size after:"
	du -sh $(PKG_TMP_BIN_PATH)/$(PKG_NAME)
	echo "Copying $(PKG_TMP_BIN_PATH)/$(PKG_NAME) binary to $(PKG_BIN_PATH) directory..."
	du -sh $(PKG_TMP_BIN_PATH)/.

	# Copy only Linux binary for the Docker image build process
	echo "Copying Linux binary from $(PKG_TMP_BIN_PATH) to $(PKG_BIN_PATH) directory..."
	cp -rf $(PKG_TMP_BIN_PATH)/$(PKG_NAME) $(PKG_BIN_PATH)/
	echo "Release size shrinking completed!"

	echo "Releases size shrinking completed!"
endef

# Creates release files (tarballs, zipballs) 
@@ -152,19 +165,25 @@ define build_release_files =
	set -e
	set -u

	echo "Creating tarballs with their checksums..."

	# Enter to bin/ directory
	mkdir -p $(PKG_BIN_PATH)
	cd $(PKG_BIN_PATH)
	pwd

	# Linux
	# Tar/Gzip/sha256sum file for Linux
	tar czvf $(PKG_RELEASE_NAME).tar.gz -C $(PKG_TMP_BIN_PATH) $(PKG_NAME)
	sha256sum $(PKG_RELEASE_NAME).tar.gz > $(PKG_NAME)-v$(PKG_TAG)-SHA256SUM
	echo "Linux tarball with sha256sum created."

	# Darwin
	# Tar/Gzip/sha256sum file for Darwin
	tar czvf $(PKG_RELEASE_NAME_DARWIN).tar.gz -C $(PKG_TMP_BIN_PATH_DARWIN) $(PKG_NAME)
	sha256sum $(PKG_RELEASE_NAME_DARWIN).tar.gz >> $(PKG_NAME)-v$(PKG_TAG)-SHA256SUM
	echo "Darwin tarball with sha256sum created."

	du -sh ./*
	echo "Release tarball files created!"
	echo "Release tarballs and sha256sum files created!"
endef

prod.release: