From f1d575b1009f7986076b1960da85b2646c60a7ca Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 14 Dec 2024 00:30:41 +0300 Subject: [PATCH 1/5] refactor(build): Abstract host module filetype handling to macro --- CMakeLists.txt | 2 +- Makefile.am | 20 ++++++++++---------- build-aux/que_libext.m4 | 15 +++++++++++++++ build-aux/que_rust_boilerplate.m4 | 4 +++- build-aux/que_rust_module.am | 8 ++++---- configure.ac | 17 ++--------------- core/pathsetup.lua.in | 4 ++-- 7 files changed, 37 insertions(+), 33 deletions(-) create mode 100644 build-aux/que_libext.m4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f362b3ba..037abcc05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -210,7 +210,7 @@ target_link_options(svg PUBLIC /EXPORT:luaopen_svg) set(LUA "luajit.exe") set(SILE_PATH "debug.getinfo(1, 'S').source:match('@?.*[/\\\\]') or '.'") set(SILE_LIB_PATH "debug.getinfo(1, 'S').source:match('@?.*[/\\\\]') or '.'") -set(SHARED_LIB_EXT "dll") +set(LIBEXT "dll") configure_file(sile.in sile.lua) if (WIN32) diff --git a/Makefile.am b/Makefile.am index 19ba5b72f..cfd27a33c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -134,7 +134,7 @@ $(CARGO_BIN): justenough/.libs/justenoughlibtexpdf.a $(CARGO_BIN): justenough/.libs/svg.a $(CARGO_BIN): libtexpdf/.libs/libtexpdf.a if !EMBEDDED_RESOURCES -$(CARGO_BIN): rusile.$(SHARED_LIB_EXT) +$(CARGO_BIN): rusile$(LIBEXT) endif !EMBEDDED_RESOURCES src/embed-includes.rs: Makefile-distfiles @@ -268,13 +268,13 @@ _DOCS_DEPS = $(and $$(filter documentation/%,$@),$(addprefix .fonts/,$(DOCSFONTF _SUBDIR_TELLS = if SHARED -_SUBDIR_TELLS += justenough/.libs/fontmetrics.$(SHARED_LIB_EXT) \ - justenough/.libs/justenoughfontconfig.$(SHARED_LIB_EXT) \ - justenough/.libs/justenoughharfbuzz.$(SHARED_LIB_EXT) \ - justenough/.libs/justenoughicu.$(SHARED_LIB_EXT) \ - justenough/.libs/justenoughlibtexpdf.$(SHARED_LIB_EXT) \ - justenough/.libs/svg.$(SHARED_LIB_EXT) \ - libtexpdf/.libs/libtexpdf.$(SHARED_LIB_EXT).0.0.0 +_SUBDIR_TELLS += justenough/.libs/fontmetrics$(LIBEXT) \ + justenough/.libs/justenoughfontconfig$(LIBEXT) \ + justenough/.libs/justenoughharfbuzz$(LIBEXT) \ + justenough/.libs/justenoughicu$(LIBEXT) \ + justenough/.libs/justenoughlibtexpdf$(LIBEXT) \ + justenough/.libs/svg$(LIBEXT) \ + libtexpdf/.libs/libtexpdf$(LIBEXT).0.0.0 endif if STATIC @@ -382,10 +382,10 @@ typos: busted: $(SILELUA) $(addprefix .fonts/,$(TESTFONTFILES)) $(BUSTEDSPECS) set -f; IFS=';' packagepath=(./{,lua-libraries/}?{,/init}.lua) - packagecpath=(./{,core/,{libtexpdf,justenough}/.libs/}?.$(SHARED_LIB_EXT)) + packagecpath=(./{,core/,{libtexpdf,justenough}/.libs/}?$(LIBEXT)) if !SYSTEM_LUAROCKS packagepath+=(./lua_modules/share/lua/$(LUA_VERSION)/?{,/init}.lua) - packagecpath+=(./lua_modules/lib/lua/$(LUA_VERSION)/?.$(SHARED_LIB_EXT)) + packagecpath+=(./lua_modules/lib/lua/$(LUA_VERSION)/?$(LIBEXT)) endif # Note: Busted tests can't run with out static build since the Rusile module is # only available embedded into it. We can test on the dynamic builds where it diff --git a/build-aux/que_libext.m4 b/build-aux/que_libext.m4 new file mode 100644 index 000000000..d8707bf5b --- /dev/null +++ b/build-aux/que_libext.m4 @@ -0,0 +1,15 @@ +dnl Note: requires AC_CANONICAL_TARGET to run before AC_INIT +AC_DEFUN_ONCE([QUE_LIBEXT], [ + case $target_os in + darwin*) + LIBEXT=.dylib + ;; + cygwin*|mingw*) + LIBEXT=.dll + ;; + *) + LIBEXT=.so + ;; + esac + AC_SUBST([LIBEXT]) +]) diff --git a/build-aux/que_rust_boilerplate.m4 b/build-aux/que_rust_boilerplate.m4 index b9f63f802..1b8ed7b11 100644 --- a/build-aux/que_rust_boilerplate.m4 +++ b/build-aux/que_rust_boilerplate.m4 @@ -47,11 +47,13 @@ $($SED -E "s/@PACKAGE_VAR@/$PACKAGE_VAR/g;s/@PACKAGE_NAME@/$PACKAGE_NAME/g" buil AC_DEFUN([QUE_RUST_MODULE], [ + QUE_LIBEXT AC_REQUIRE([AX_AM_MACROS]) + AX_ADD_AM_MACRO([dnl EXTRA_DIST += build-aux/que_rust_module.am -$($SED -E "s/@MODULE@/$1/g;s/@SHARED_LIB_EXT@/$SHARED_LIB_EXT/g" build-aux/que_rust_module.am) +$($SED -E "s/@MODULE@/$1/g;s/@LIBEXT@/$LIBEXT/g;s/@_LIBEXT@/${LIBEXT##.}/g" build-aux/que_rust_module.am) ])dnl ]) diff --git a/build-aux/que_rust_module.am b/build-aux/que_rust_module.am index 5054e5242..1646e25d7 100644 --- a/build-aux/que_rust_module.am +++ b/build-aux/que_rust_module.am @@ -1,8 +1,8 @@ -pkglib_LIBRARIES = @MODULE@.@SHARED_LIB_EXT@ -@MODULE@_@SHARED_LIB_EXT@_SOURCES = @MODULE@/Cargo.toml @MODULE@/src/lib.rs @MODULE@/build.rs +pkglib_LIBRARIES = @MODULE@@LIBEXT@ +@MODULE@_@_LIBEXT@_SOURCES = @MODULE@/Cargo.toml @MODULE@/src/lib.rs @MODULE@/build.rs -@builddir@/target/@RUST_TARGET_SUBDIR@/lib@MODULE@.@SHARED_LIB_EXT@: $(@MODULE@_@SHARED_LIB_EXT@_SOURCES) +@builddir@/target/@RUST_TARGET_SUBDIR@/lib@MODULE@@LIBEXT@: $(@MODULE@_@_LIBEXT@_SOURCES) $(CARGO_ENV) $(CARGO) build $(CARGO_VERBOSE) --target $(CARGO_TARGET_TRIPLE) $(@MODULE@_FEATURE_ARGS) $(CARGO_RELEASE_ARGS) -p @MODULE@ -@MODULE@.@SHARED_LIB_EXT@: @builddir@/target/@RUST_TARGET_SUBDIR@/lib@MODULE@.@SHARED_LIB_EXT@ +@MODULE@@LIBEXT@: @builddir@/target/@RUST_TARGET_SUBDIR@/lib@MODULE@@LIBEXT@ $(INSTALL) $< $@ diff --git a/configure.ac b/configure.ac index 72473ee63..2a3c8e905 100644 --- a/configure.ac +++ b/configure.ac @@ -11,6 +11,7 @@ QUE_GIT_VERSION QUE_TRANSFORM_PACKAGE_NAME QUE_DEVELOPER_MODE QUE_DIST_CHECKSUMS +QUE_LIBEXT # Extend the QUE checksums feature with support for the PDF manual SILE_DIST_CHECKSUMS @@ -38,22 +39,8 @@ RANLIB=: LT_PREREQ([2.2]) LT_INIT([dlopen]) -QUE_RUST_BOILERPLATE QUE_DOCKER_BOILERPLATE - -# Load Rust module bits, early since it stuffs rules in aminclude.am -case $target_os in - darwin*) - SHARED_LIB_EXT="dylib" - ;; - cygwin*|mingw*) - SHARED_LIB_EXT="dll" - ;; - *) - SHARED_LIB_EXT="so" - ;; -esac -AC_SUBST([SHARED_LIB_EXT]) +QUE_RUST_BOILERPLATE QUE_RUST_MODULE([rusile]) AM_CONDITIONAL([SHARED], [test "x$enable_shared" = "xyes"]) diff --git a/core/pathsetup.lua.in b/core/pathsetup.lua.in index 3ad11b287..9c7ec4c41 100644 --- a/core/pathsetup.lua.in +++ b/core/pathsetup.lua.in @@ -42,8 +42,8 @@ end -- Prepend paths specifically for C modules. local function prependCPath (path) - package.cpath = prepend_and_dedup(path .. "/?.@SHARED_LIB_EXT@", package.cpath) - if "@SHARED_LIB_EXT@" ~= "so" then + package.cpath = prepend_and_dedup(path .. "/?@LIBEXT@", package.cpath) + if "@LIBEXT@" ~= "so" then package.cpath = prepend_and_dedup(path .. "/?.so", package.cpath) end end From a5758e1397ebe092458b83f97e6fa9d87b1af239 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 4 Jan 2025 11:34:33 +0300 Subject: [PATCH 2/5] chore(build): Disable automake's irrelevant-to-us dependency tracking --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 2a3c8e905..22713e306 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_INIT([sile], [m4_esyscmd(build-aux/git-version-gen .tarball-version)], [caleb AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([build-aux]) AC_CANONICAL_TARGET -AM_INIT_AUTOMAKE([foreign tar-pax dist-zstd dist-zip no-dist-gzip color-tests subdir-objects]) +AM_INIT_AUTOMAKE([foreign tar-pax dist-zstd dist-zip no-dist-gzip no-dependencies color-tests subdir-objects]) AM_SILENT_RULES([yes]) # Load up re-usable m4 bits shared across Caleb's projects From 4493ef78f1dcff353510018fcd52c3411f5013af Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 4 Jan 2025 12:34:33 +0300 Subject: [PATCH 3/5] chore(build): Remove obsolete Darwin workarounds --- bootstrap.sh | 9 --------- 1 file changed, 9 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 2bb636c3a..f305cca6b 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -47,13 +47,4 @@ touch aminclude.am autoreconf --install -# See discussion in https://github.com/sile-typesetter/sile/issues/82 and -# https://web.archive.org/web/20170111053341/http://blog.gaku.net/autoconf/ -case $(uname) in - Darwin*) - glibtoolize -W none - autoreconf --force -W none - ;; -esac - build-aux/decore-automake.sh From 15a20e034c10f31af8316aec75829a0febe0ffc0 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Thu, 26 Dec 2024 15:57:33 +0300 Subject: [PATCH 4/5] fix(build): Re-organize rules so sources don't have platform detection artifacts --- Makefile.am | 3 ++- build-aux/que_libext.m4 | 3 +++ build-aux/que_rust_boilerplate.m4 | 2 +- build-aux/que_rust_module.am | 40 +++++++++++++++++++++++++++---- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index cfd27a33c..3d7586ccb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -59,6 +59,7 @@ BUILT_SOURCES_LUA = core/features.lua core/pathsetup.lua core/version.lua bin_PROGRAMS = sile bin_SCRIPTS = sile-lua +pkglib_LIBRARIES = nodist_man_MANS = dist_man_MANS = sile-lua.1 sile_SOURCES = src/bin/sile.rs src/lib.rs src/cli.rs src/types.rs src/types/semver.rs @@ -134,7 +135,7 @@ $(CARGO_BIN): justenough/.libs/justenoughlibtexpdf.a $(CARGO_BIN): justenough/.libs/svg.a $(CARGO_BIN): libtexpdf/.libs/libtexpdf.a if !EMBEDDED_RESOURCES -$(CARGO_BIN): rusile$(LIBEXT) +$(CARGO_BIN): $(pkglib_LIBRARIES) endif !EMBEDDED_RESOURCES src/embed-includes.rs: Makefile-distfiles diff --git a/build-aux/que_libext.m4 b/build-aux/que_libext.m4 index d8707bf5b..f1ff2b16a 100644 --- a/build-aux/que_libext.m4 +++ b/build-aux/que_libext.m4 @@ -11,5 +11,8 @@ AC_DEFUN_ONCE([QUE_LIBEXT], [ LIBEXT=.so ;; esac + AM_CONDITIONAL([LIB_IS_SO], [test $LIBEXT = .so]) + AM_CONDITIONAL([LIB_IS_DYLIB], [test $LIBEXT = .dylib]) + AM_CONDITIONAL([LIB_IS_DLL], [test $LIBEXT = .dll]) AC_SUBST([LIBEXT]) ]) diff --git a/build-aux/que_rust_boilerplate.m4 b/build-aux/que_rust_boilerplate.m4 index 1b8ed7b11..f1fe47214 100644 --- a/build-aux/que_rust_boilerplate.m4 +++ b/build-aux/que_rust_boilerplate.m4 @@ -53,7 +53,7 @@ AC_DEFUN([QUE_RUST_MODULE], [ AX_ADD_AM_MACRO([dnl EXTRA_DIST += build-aux/que_rust_module.am -$($SED -E "s/@MODULE@/$1/g;s/@LIBEXT@/$LIBEXT/g;s/@_LIBEXT@/${LIBEXT##.}/g" build-aux/que_rust_module.am) +$($SED -E "s/@MODULE@/$1/g" build-aux/que_rust_module.am) ])dnl ]) diff --git a/build-aux/que_rust_module.am b/build-aux/que_rust_module.am index 1646e25d7..2760f99d8 100644 --- a/build-aux/que_rust_module.am +++ b/build-aux/que_rust_module.am @@ -1,8 +1,40 @@ -pkglib_LIBRARIES = @MODULE@@LIBEXT@ -@MODULE@_@_LIBEXT@_SOURCES = @MODULE@/Cargo.toml @MODULE@/src/lib.rs @MODULE@/build.rs +@MODULE@_srcs = @MODULE@/Cargo.toml @MODULE@/src/lib.rs @MODULE@/build.rs -@builddir@/target/@RUST_TARGET_SUBDIR@/lib@MODULE@@LIBEXT@: $(@MODULE@_@_LIBEXT@_SOURCES) +if LIB_IS_SO +pkglib_LIBRARIES += rusile.so +@MODULE@_so_SOURCES = $(@MODULE@_srcs) +endif + +if LIB_IS_DYLIB +pkglib_LIBRARIES += rusile.dylib +@MODULE@_dylib_SOURCES = $(@MODULE@_srcs) +endif + +if LIB_IS_DLL +pkglib_LIBRARIES += rusile.dll +@MODULE@_dll_SOURCES = $(@MODULE@_srcs) +endif + +@MODULE@_so_AR = : +@MODULE@_so_RANLIB = : +@MODULE@_so_LINK = : + +@MODULE@_dylib_AR = : +@MODULE@_dylib_RANLIB = : +@MODULE@_dylib_LINK = : + +@MODULE@_dll_AR = : +@MODULE@_dll_RANLIB = : +@MODULE@_dll_LINK = : + +@builddir@/target/@RUST_TARGET_SUBDIR@/lib@MODULE@.so @builddir@/target/@RUST_TARGET_SUBDIR@/lib@MODULE@.dylib @builddir@/target/@RUST_TARGET_SUBDIR@/lib@MODULE@.dll: $(@MODULE@_srcs) $(CARGO_ENV) $(CARGO) build $(CARGO_VERBOSE) --target $(CARGO_TARGET_TRIPLE) $(@MODULE@_FEATURE_ARGS) $(CARGO_RELEASE_ARGS) -p @MODULE@ -@MODULE@@LIBEXT@: @builddir@/target/@RUST_TARGET_SUBDIR@/lib@MODULE@@LIBEXT@ +@MODULE@.so: @builddir@/target/@RUST_TARGET_SUBDIR@/lib@MODULE@.so + $(INSTALL) $< $@ + +@MODULE@.dylib: @builddir@/target/@RUST_TARGET_SUBDIR@/lib@MODULE@.dylib + $(INSTALL) $< $@ + +@MODULE@.dll: @builddir@/target/@RUST_TARGET_SUBDIR@/lib@MODULE@.dll $(INSTALL) $< $@ From 5805cd47abb89eef1b27b411341b4599b7622813 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 4 Jan 2025 12:14:32 +0300 Subject: [PATCH 5/5] fix(build): Correct dependencies in non-embedded mode --- Makefile.am | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index 3d7586ccb..0f3add964 100644 --- a/Makefile.am +++ b/Makefile.am @@ -134,9 +134,6 @@ $(CARGO_BIN): justenough/.libs/justenoughicu.a $(CARGO_BIN): justenough/.libs/justenoughlibtexpdf.a $(CARGO_BIN): justenough/.libs/svg.a $(CARGO_BIN): libtexpdf/.libs/libtexpdf.a -if !EMBEDDED_RESOURCES -$(CARGO_BIN): $(pkglib_LIBRARIES) -endif !EMBEDDED_RESOURCES src/embed-includes.rs: Makefile-distfiles { @@ -154,7 +151,10 @@ src/embed.rs: src/embed.rs.in src/embed-includes.rs -e '/@EMBEDDED_INCLUDE_LIST@/r $(word 2,$^)' \ -e '/@EMBEDDED_INCLUDE_LIST@/d' \ $< > $@ -endif EMBEDDED_RESOURCES + +else !EMBEDDED_RESOURCES +$(CARGO_BIN): $(pkglib_LIBRARIES) +endif !EMBEDDED_RESOURCES if LUAJIT MLUAVER = luajit