Skip to content

Commit

Permalink
Merge pull request #2072 from sile-typesetter/cargo-workspace-inplace
Browse files Browse the repository at this point in the history
Setup Lua module for exporting Rust functions to Lua
  • Loading branch information
alerque authored Nov 2, 2024
2 parents f864fa1 + 155dc89 commit da1829c
Show file tree
Hide file tree
Showing 16 changed files with 337 additions and 130 deletions.
1 change: 1 addition & 0 deletions .commitlintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ rules:
- pdf
- readme
- release
- rusile
- settings
- shapers
- tooling
Expand Down
25 changes: 18 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 31 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
[package]
name = "sile"
[workspace]
resolver = "2"
members = [
".",
"rusile",
]

[workspace.package]
version = "0.15.5"
edition = "2021"
rust-version = "1.71.0"
description = "Simon’s Improved Layout Engine"
authors = [
"Simon Cozens",
"Caleb Maclennan <[email protected]>",
"Olivier Nicole",
"Didier Willis"
]
readme = "README.md"
homepage = "https://sile-typesetter.org"
repository = "https://github.com/sile-typesetter/sile"
license = "MIT"

[package]
name = "sile"
description = "Simon’s Improved Layout Engine"
readme = "README.md"
build = "build-aux/build.rs"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true
license.workspace = true

[package.metadata.bacon.jobs]
cmd = [ "cargo", "build", "--color", "always" ]

[package.metadata.typos.default]
locale = "en-us"
Expand Down Expand Up @@ -91,6 +110,10 @@ zsh = [ "completions" ]
[profile.release]
lto = true

[workspace.dependencies.mlua]
version = "0.10.0"
features = [ "anyhow" ]

[dependencies.anyhow]
version = "1.0"

Expand All @@ -100,7 +123,7 @@ optional = true
features = [ "derive", "string", "wrap_help" ]

[dependencies.mlua]
version = "0.9"
workspace = true
features = [ "macros" ]

[dependencies.rust-embed]
Expand All @@ -112,6 +135,9 @@ features = [ "include-exclude" ]
version = "0.5"
optional = true

[dependencies.semver]
version = "1.0"

[build-dependencies.clap_complete]
version = "4.4"
optional = true
Expand Down
48 changes: 35 additions & 13 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,21 @@ endif

$(MANUAL): $(FIGURES)

BUILT_LUA_SOURCES = core/features.lua core/pathsetup.lua core/version.lua
BUILT_SOURCES_LUA = core/features.lua core/pathsetup.lua core/version.lua
RUSILE_SOURCES = rusile/Cargo.toml rusile/src/lib.rs

bin_PROGRAMS = sile
bin_SCRIPTS = sile-lua
nodist_man_MANS =
dist_man_MANS = sile-lua.1
sile_SOURCES = src/bin/sile.rs src/lib.rs src/cli.rs
sile_SOURCES = src/bin/sile.rs src/lib.rs src/cli.rs src/types.rs src/types/semver.rs
EXTRA_sile_SOURCES =
if !EMBEDDED_RESOURCES
nobase_dist_pkgdata_DATA = $(SILEDATA) $(LUALIBRARIES)
nobase_nodist_pkgdata_DATA = $(BUILT_LUA_SOURCES) $(LUAMODULES)
endif
nobase_nodist_pkgdata_DATA = $(BUILT_SOURCES_LUA) $(LUAMODULES)
pkglib_LIBRARIES = rusile.so
rusile_so_SOURCES = $(RUSILE_SOURCES)
endif !EMBEDDED_RESOURCES
dist_doc_DATA = README.md CHANGELOG.md
dist_pdf_DATA = $(_MANUAL)
dist_license_DATA = LICENSE.md
Expand All @@ -83,7 +86,13 @@ if EMBEDDED_RESOURCES
EXTRA_DIST += $(SILEDATA) $(LUALIBRARIES)
endif

BUILT_SOURCES = $(BUILT_LUA_SOURCES) Makefile-distfiles
BUILT_SOURCES = $(BUILT_SOURCES_LUA) Makefile-distfiles

if SHARED
EXTRA_RUNTIME_DEPS = $(pkglib_LIBRARIES)
else !SHARED
EXTRA_RUNTIME_DEPS =
endif

CLEANFILES = $(MANUAL)

Expand Down Expand Up @@ -122,11 +131,15 @@ $(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): rusile.so
endif !EMBEDDED_RESOURCES

src/embed-includes.rs: Makefile-distfiles
{
echo $(BUILT_LUA_SOURCES)
$(GREP) -E '^(SILEDATA|LUALIBRARIES|LUAMODULES) = ' $<
echo $(BUILT_SOURCES_LUA)
$(SED) -ze 's/\\\n\t//g' $< |
$(GREP) -E '^(SILEDATA|LUALIBRARIES|LUAMODULES) = '
} |
$(SED) -E -e 's/^.* = //;s/ /\n/g' |
while read file; do
Expand All @@ -146,6 +159,7 @@ else
MLUAVER = lua$(LUA_SHORT_VERSION)
endif
CARGO_FEATURE_ARGS = --features $(MLUAVER)
RUSILE_FEATURE_ARG = --features $(MLUAVER)

if !SYSTEM_LUA_SOURCES
CARGO_FEATURE_ARGS += --features vendored
Expand All @@ -159,6 +173,10 @@ if FONT_VARIATIONS
CARGO_FEATURE_ARGS += --features variations
endif

rusile.so: $(rusile_so_SOURCES) $(bin_PROGRAMS)
$(CARGO_ENV) $(CARGO) build $(CARGO_VERBOSE) $(RUSILE_FEATURE_ARG) $(CARGO_RELEASE_ARGS) -p rusile
$(INSTALL) @builddir@/target/@RUST_TARGET_SUBDIR@/lib$@ $@

DEPDIR := .deps
LOCALFONTS := FONTCONFIG_FILE=$(PWD)/fontconfig.conf
LOCALPATHS := SILE_PATH="$(PWD);libtexpdf/.libs;justenough/.libs"
Expand Down Expand Up @@ -198,7 +216,7 @@ sile-%.md: CHANGELOG.md
check: selfcheck

.PHONY: selfcheck
selfcheck: | $(bin_PROGRAMS) $(_BUILT_SUBDIRS)
selfcheck: | $(bin_PROGRAMS) $(_BUILT_SUBDIRS) $(EXTRA_RUNTIME_DEPS)
output=$$(mktemp -t selfcheck-XXXXXX.pdf)
trap '$(RM) $$output' EXIT HUP TERM
echo "<sile>foo</sile>" | $(LOCALPATHS) ./$(bin_PROGRAMS) -o $$output -
Expand Down Expand Up @@ -249,9 +267,6 @@ _FORCED = $(and $(SILE_COVERAGE)$(CLEAN),force)
_TEST_DEPS = $(and $$(filter tests/%,$@),$(addprefix .fonts/,$(TESTFONTFILES)))
_DOCS_DEPS = $(and $$(filter documentation/%,$@),$(addprefix .fonts/,$(DOCSFONTFILES)))

# TODO: remove _BUILT_SUBDIRS hack and replace it with something sensible when
# these subdirs don't do crazy things like copying files outside of their own trees!
_BUILT_SUBDIRS = .built-subdirs
_SUBDIR_TELLS =

if SHARED
Expand Down Expand Up @@ -282,7 +297,7 @@ CLEANFILES += $(_BUILT_SUBDIRS)
$(_SUBDIR_TELLS):
$(MAKE) $(AM_MAKEFLAGS) all-recursive

patterndeps = $(_FORCED) $(_TEST_DEPS) $(_DOCS_DEPS) | $(bin_PROGRAMS) $(DEPDIRS) $(LUAMODLOCK) $(_BUILT_SUBDIRS)
patterndeps = $(_FORCED) $(_TEST_DEPS) $(_DOCS_DEPS) | $(bin_PROGRAMS) $(EXTRA_RUNTIME_DEPS) $(DEPDIRS) $(LUAMODLOCK) $(_BUILT_SUBDIRS)

%.pdf: %.sil $$(patterndeps)
$(runsile)
Expand Down Expand Up @@ -365,8 +380,15 @@ if !SYSTEM_LUAROCKS
packagepath+=(./lua_modules/share/lua/$(LUA_VERSION)/?{,/init}.lua)
packagecpath+=(./lua_modules/lib/lua/$(LUA_VERSION)/?.$(SHARED_LIB_EXT))
endif
# Note: use of --lua causes this to be passed back through a shell loosing one layer of quoting. Drop single quotes if removing.
# 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
# is available as a use space module. This could change if we enable a lua vm
# pass through mode and use that as busted's interpreter.
if SHARED
# Note: use of --lua causes this to be passed back through a shell loosing one
# layer of quoting. Drop single quotes if removing.
$(LOCALFONTS) $(BUSTED) --lua=$(LUA) --lpath="'$${packagepath[*]};;'" --cpath="'$${packagecpath[*]};;'" $(BUSTEDFLAGS) .
endif

coverage: export SILE_COVERAGE=1
coverage: BUSTEDFLAGS += -c
Expand Down
2 changes: 1 addition & 1 deletion build-aux/que_rust_boilerplate.am
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ $(COMPLETIONS_OUT_DIR)/_$(TRANSFORMED_PACKAGE_NAME).ps1: $(CARGO_BIN) | $(COMPLE
$(COMPLETIONS_OUT_DIR)/_$(TRANSFORMED_PACKAGE_NAME): $(CARGO_BIN) | $(COMPLETIONS_OUT_DIR)
$(INSTALL) -m755 $$(cat $(_RUST_OUT))/$(COMPLETIONS_OUT_DIR)/_$(PACKAGE_NAME) $@

$(_RUST_OUT) $(CARGO_BIN): $(@PACKAGE_VAR@_SOURCES) $(EXTRA_@PACKAGE_VAR@_SOURCES)
$(_RUST_OUT) $(CARGO_BIN): $(@PACKAGE_VAR@_SOURCES) $(nodist_@PACKAGE_VAR@_SOURCES) $(EXTRA_@PACKAGE_VAR@_SOURCES)
set -e
export AUTOTOOLS_DEPENDENCIES="$^"
$(CARGO_ENV) $(CARGO) build $(CARGO_VERBOSE) $(CARGO_FEATURE_ARGS) $(CARGO_RELEASE_ARGS)
Expand Down
4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ QUE_PROGVAR([pdfinfo])
QUE_PROGVAR([sort])
QUE_PROGVAR([xargs])

# Disable ranlib to avoid it being run on our rusile.so module, already LTO
# optimized but libtool wants to relink it...
RANLIB=:

LT_PREREQ([2.2])
LT_INIT([dlopen])

Expand Down
2 changes: 1 addition & 1 deletion core/utilities/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

local bitshim = require("bitshim")
local luautf8 = require("lua-utf8")
local semver = require("semver")
local semver = require("rusile").semver

local utilities = {}

Expand Down
46 changes: 0 additions & 46 deletions lua-libraries/semver.lua

This file was deleted.

2 changes: 1 addition & 1 deletion packages/retrograde/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local base = require("packages.base")
local package = pl.class(base)
package._name = "retrograde"

local semver = require("semver")
local semver = require("rusile").semver

local semver_descending = function (a, b)
a, b = semver(a), semver(b)
Expand Down
30 changes: 30 additions & 0 deletions rusile/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "rusile"
description = "Rusty components for the SILE typesetter"
readme = "README.md"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true
license.workspace = true

[lib]
crate-type = ["rlib", "cdylib", "staticlib"]

[dependencies.sile]
path = ".."

[features]
default = []
lua54 = [ "mlua/lua54" ]
lua53 = [ "mlua/lua53" ]
lua52 = [ "mlua/lua52" ]
lua51 = [ "mlua/lua51" ]
luajit = [ "mlua/luajit" ]
vendored = [ "mlua/vendored" ]

[dependencies.mlua]
workspace = true
features = [ "macros", "module" ]
Loading

0 comments on commit da1829c

Please sign in to comment.