From 58ce7008021b54f6d9fa41450184f42fd673ffee Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 20 Oct 2020 14:04:16 +0300 Subject: [PATCH] feat(build): Package CLI built from Rust instead of Python sources --- Makefile.am | 45 ++++++++++++++++++++++++++++++++++++++++----- bootstrap.sh | 4 +++- configure.ac | 28 +++++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/Makefile.am b/Makefile.am index e91c19b..9ae8902 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,23 +5,58 @@ _fontship = $(shell sed -e "$(program_transform_name)" <<< fontship) licensedir = $(datarootdir)/licenses/$(_fontship) datadir = $(datarootdir)/$(_fontship) -bin_SCRIPTS = $(_fontship) -python_PYTHON = $(_fontship).py dist_doc_DATA = README.md CHANGELOG.md dist_man_MANS = $(_fontship).1 dist_license_DATA = LICENSE -dist_data_DATA = rules/fontship.mk rules/rules.mk rules/functions.mk rules/glyphs.mk rules/sfd.mk rules/ufo.mk +nobase_dist_data_DATA = rules/fontship.mk rules/rules.mk rules/functions.mk rules/glyphs.mk rules/sfd.mk rules/ufo.mk EXTRA_DIST = .version Dockerfile +bin_PROGRAMS = fontship + +_fontship_libs = src/lib.rs src/cli.rs src/config.rs src/i18n.rs +_fontship_modules = src/make/mod.rs src/setup/mod.rs src/status/mod.rs +_fontship_assets = assets/en-US/cli.ftl +fontship_SOURCES = Cargo.toml build.rs src/main.rs $(_fontship_libs) $(_fontship_modules) $(_fontship_assets) +EXTRA_fontship_SOURCES = Cargo.lock + BUILT_SOURCES = .version -CLEANFILES = $(BUILT_SOURCES) $(bin_SCRIPTS) +CLEANFILES = $(BUILT_SOURCES) $(bin_PROGRAMS) .version: $(shell test -e .git && awk '{print ".git/" $$2}' .git/HEAD) mv $@{,-prev} 2>/dev/null || touch $@-prev ( test -e .git && ./build-aux/git-version-gen .tarball-version || echo $(VERSION) ) > $@ cmp -s $@{,-prev} || autoreconf configure.ac --force -W none +if DEBUG_RELEASE +CARGO_RELEASE_ARGS=--locked --all-features +else +CARGO_RELEASE_ARGS=--release --locked --all-features +endif + +# Leave some tips for cargo to use so CLI knows where it is +export CONFIGURE_PREFIX = $(prefix)/ +export CONFIGURE_DATADIR = $(datadir)/ +export CONFIGURE_BINDIR = $(bindir)/ + +CARGO_VERBOSE = $(cargo_verbose_$(V)) +cargo_verbose_ = $(cargo_verbose_$(AM_DEFAULT_VERBOSITY)) +cargo_verbose_0 = +cargo_verbose_1 = --verbose + +CARGO_TARGET = target/release/fontship + +fontship$(EXEEXT): $(CARGO_TARGET) + cp -bf $< $@ + +$(CARGO_TARGET): $(fontship_SOURCES) clean-embedded-assets + cargo build $(CARGO_VERBOSE) $(CARGO_RELEASE_ARGS) + +.PHONY: clean-embedded-assets +clean-embedded-assets: + [[ -d .git ]] || exit 0 + git clean -dxf assets + dist: fontship-$(VERSION).md dist-hook: @@ -30,7 +65,7 @@ dist-hook: check: selfcheck .PHONY: selfcheck -selfcheck: $(bin_SCRIPTS) | $(BUILT_SOURCES) +selfcheck: $(_fontship) | $(BUILT_SOURCES) ./$< --version | grep -Ff $(firstword $|) RELTYPE ?= diff --git a/bootstrap.sh b/bootstrap.sh index 1620b54..493bffd 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -20,4 +20,6 @@ else ./build-aux/git-version-gen .tarball-version > .version fi -autoreconf --install -W none +autoreconf --symlink --install --warnings=none +aclocal --force -W none +automake --force-missing --add-missing -W none diff --git a/configure.ac b/configure.ac index fa5f8f0..b6e8f63 100644 --- a/configure.ac +++ b/configure.ac @@ -4,6 +4,33 @@ AC_INIT([fontship], AM_INIT_AUTOMAKE([foreign tar-pax dist-xz dist-zip no-dist-gzip color-tests]) AM_SILENT_RULES([yes]) +# Check that we have rust stuff +AC_CHECK_PROG(CARGO, [cargo], [yes], [no]) +AS_IF(test x$CARGO = xno, + AC_MSG_ERROR([cargo is required. Please install the Rust toolchain]) +) +AC_CHECK_PROG(RUSTC, [rustc], [yes], [no]) +AS_IF(test x$RUSTC = xno, + AC_MSG_ERROR([rustc is required. Please install the Rust toolchain]) +) + +# Add --enable-debug flag to change Rust build mode +AC_ARG_ENABLE(debug, + AC_HELP_STRING([--enable-debug], + [Build Rust code with debugging information [default=no]]), + [debug_release=$enableval], + [debug_release=no]) + +AC_MSG_CHECKING(whether to build Rust code with debugging information) +if test "x$debug_release" = "xyes" ; then + AC_MSG_RESULT(yes) + RUST_TARGET_SUBDIR=debug +else + AC_MSG_RESULT(no) + RUST_TARGET_SUBDIR=release +fi +AM_CONDITIONAL([DEBUG_RELEASE], [test "x$debug_release" = "xyes"]) + AC_CHECK_PROG(GFTOOLS, gftools, yes) test "x$GFTOOLS" == "xyes" || AC_MSG_ERROR([gftools is required]) @@ -41,6 +68,5 @@ fi AC_SUBST([MAN_DATE]) AC_CONFIG_FILES([Makefile fontship.1]) -AC_CONFIG_FILES([fontship], [chmod +x fontship]) AC_OUTPUT