From da94442fae40736859787575b65720382c1f231c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 3 Oct 2020 18:24:56 +0200 Subject: Build for release and configure static linking Set up a release build and distribution packaging. Configure static linking for 'openssl' and 'libgit2'. Based on or copied from code from 'git-suggestion'. --- .gitignore | 1 + Cargo.lock | 10 ++++++++++ Cargo.toml | 2 +- Makefile | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ea8c4bf..48681a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +/dist/ /target diff --git a/Cargo.lock b/Cargo.lock index abaac2e..b0ca986 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -154,6 +154,15 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" +[[package]] +name = "openssl-src" +version = "111.11.0+1.1.1h" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380fe324132bea01f45239fadfec9343adb044615f29930d039bec1ae7b9fa5b" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.58" @@ -163,6 +172,7 @@ dependencies = [ "autocfg", "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] diff --git a/Cargo.toml b/Cargo.toml index 69bbb52..961de83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,5 +6,5 @@ edition = "2018" [dependencies] exitcode = "1.1.2" getopts = "0.2.21" -git2 = "0.13.11" +git2 = { version = "0.13.11", features = ["vendored-openssl"] } thiserror = "1.0.20" diff --git a/Makefile b/Makefile index c01ae66..8a4116d 100644 --- a/Makefile +++ b/Makefile @@ -14,15 +14,33 @@ # along with this program. If not, see . +VERSION := $(shell egrep '^version = ' Cargo.toml | awk -F '"' '{ print $$2 }') +TOOLCHAIN := $(shell fgrep default_host_triple $(HOME)/.rustup/settings.toml | awk -F '"' '{ print $$2 }') + SOURCES := $(shell find . -name '*.rs') DEPENDENCIES := Cargo.toml + +MAN_PAGE := doc/git-todo.1 + DEBUG_PRODUCT := target/debug/git-todo +RELEASE_PRODUCT := target/release/git-todo + +DIST := $(abspath dist) +DIST_PRODUCT := $(DIST)/bin/git-todo +DIST_MAN_PAGE := $(DIST)/share/man/man1/git-todo.1 + +# Set STATIC=1 to build a static binary. +STATIC ?= 0 + +ifeq ($(STATIC), 1) +BUILD_VARS += PKG_CONFIG_LIBDIR='' +endif .PHONY: doc -doc: doc/git-todo.1 +doc: $(MAN_PAGE) -doc/git-todo.1: doc/git-todo.1.txt +$(MAN_PAGE): doc/git-todo.1.txt sed 's/`/*/g' $< > $@.transformed a2x --no-xmllint --format manpage $@.transformed rm $@.transformed @@ -34,3 +52,33 @@ test: $(DEBUG_PRODUCT) $(DEBUG_PRODUCT): $(SOURCES) $(DEPENDENCIES) cargo build + + +$(RELEASE_PRODUCT): $(SOURCES) $(DEPENDENCIES) + $(BUILD_VARS) cargo build --release + + +.PHONY: dist +dist: $(DIST_PRODUCT) $(DIST_MAN_PAGE) + +$(DIST): + mkdir -p $@ + +$(DIST)/bin: $(DIST) + mkdir -p $@ + +$(DIST)/share/man/man1: $(DIST) + mkdir -p $@ + +$(DIST_PRODUCT): $(DIST)/bin $(RELEASE_PRODUCT) + cp $(RELEASE_PRODUCT) $< + +$(DIST_MAN_PAGE): $(DIST)/share/man/man1 $(MAN_PAGE) + cp $(MAN_PAGE) $< + + +.PHONY: pkg +pkg: git-todo_$(VERSION)_$(TOOLCHAIN).tar.bz2 + +git-todo_$(VERSION)_$(TOOLCHAIN).tar.bz2: dist + tar cjv -s /dist/git-todo_$(VERSION)_$(TOOLCHAIN)/ -f $@ dist -- cgit v1.2.3