Skip to content

Commit

Permalink
feat(build): Package CLI built from Rust instead of Python sources
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Oct 21, 2020
1 parent 399c30c commit 58ce700
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 7 deletions.
45 changes: 40 additions & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -30,7 +65,7 @@ dist-hook:
check: selfcheck

.PHONY: selfcheck
selfcheck: $(bin_SCRIPTS) | $(BUILT_SOURCES)
selfcheck: $(_fontship) | $(BUILT_SOURCES)
./$< --version | grep -Ff $(firstword $|)

RELTYPE ?=
Expand Down
4 changes: 3 additions & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 27 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down Expand Up @@ -41,6 +68,5 @@ fi
AC_SUBST([MAN_DATE])

AC_CONFIG_FILES([Makefile fontship.1])
AC_CONFIG_FILES([fontship], [chmod +x fontship])

AC_OUTPUT

0 comments on commit 58ce700

Please sign in to comment.