Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup Lua module for exporting Rust functions to Lua #2072

Merged
merged 39 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5d32d56
chore(deps): Bump pinned versions of patch level crate updates
alerque Jun 15, 2024
cd135d2
refactor(cli): Separate Rust concerns in a workspace
alerque Jun 15, 2024
33703db
chore(deps): Bump pinned versions of patch level crate updates
alerque Sep 30, 2024
055a68e
chore(deps): Upgrade mlua to beta release of v0.10
alerque Sep 30, 2024
b9716f0
refactor(cli): Update Lua VM usage with improved generic handling
alerque Sep 30, 2024
3a95a48
feat(core): Add separate crate to enable exporting interfaces to Lua
alerque Jun 15, 2024
93c6de7
test(api): Mockup how to test a Rust function from Lua
alerque Jun 15, 2024
46bcc15
chore(deps): Bump pinned versions of patch level crate updates
alerque Jun 28, 2024
7bb9a22
Merge tag 'v0.15.4' into cargo-workspace-inplace
alerque Jun 28, 2024
af9bbf5
chore(tooling): Call out Rusile module as possile commit scope
alerque Jul 2, 2024
b8534cf
refactor(rusile): Move function into sile, keep rusile as just bindings
alerque Jul 2, 2024
f590e37
chore(rusile): Hold off embedding rusile pending duplicate linking is…
alerque Jul 3, 2024
b70acd7
chore(deps): Bump pinned versions of patch level crate updates
alerque Oct 2, 2024
c0c9b9f
Merge tag 'v0.15.5' into cargo-workspace-inplace
alerque Oct 2, 2024
3e50b28
Merge branch 'mlua-v010' into cargo-workspace-inplace
alerque Oct 2, 2024
8dcccca
chore(deps): Bump mlua to RC1 of upcomming 0.10 release
alerque Oct 3, 2024
247856e
refactor(rusile): Use new anyhow feature to wrap original function
alerque Oct 3, 2024
0b06d33
chore(rusile): Update Cargo syntax for edition 2024
alerque Oct 10, 2024
b106bda
chore(deps): Add semver package, going to try to replace vendored Lua…
alerque Jun 11, 2024
7fc0351
chore(tooling): Setup bacon
alerque Oct 10, 2024
b850b24
chore(rusile): Remove demo, make room to land real stuff
alerque Oct 12, 2024
358954a
refactor(utilities): Rewrite semver in Rust and wrap as Lua type
alerque Oct 10, 2024
932252e
test(utilities): Add unit tests for semver type
alerque Oct 12, 2024
0ade15e
chore(cli): Add names to Lua code chunks to improve error messages
alerque Oct 13, 2024
f102728
chore(core): Update mlua from prerelease to stable tag
alerque Oct 26, 2024
208ce4f
refactor(core): Avoid chunk execution when enabled by mlua v0.10
alerque Oct 26, 2024
fb6b866
fix(cli): Correct return value handling when process() doesn't lift w…
alerque Nov 1, 2024
1e162f6
chore(rusile): Allow conversion of nil to semver
alerque Nov 1, 2024
dae2f7f
fix(build): Correct regression in v0.15.5 in generating embedded file…
alerque Nov 2, 2024
430a6d4
chore(cli): Don't embed unnecessary resources in static binary
alerque Nov 2, 2024
19d68bc
chore(rusile): Refactor static embeded builds for mlua 0.10
alerque Nov 1, 2024
693d7d4
feat(rusile): Enable embedding of Rusile module
alerque Nov 1, 2024
83a957a
chore(tooling): Disable busted tests for static binary build where ru…
alerque Nov 2, 2024
baf5269
refactor(utilities): Drop Lua semver implementation, use Rust one
alerque Nov 2, 2024
1ccb3c7
chore(deps): Bump pinned versions of patch level crate updates
alerque Nov 2, 2024
e646a1b
Merge branch 'master' into cargo-workspace-inplace
alerque Nov 2, 2024
02461db
chore(build): Disable RANLIB on already optimized module for all plat…
alerque Nov 2, 2024
252e674
refactor(cli): Redo option parsing enabled by mlua v0.10 scopes
alerque Nov 2, 2024
155dc89
chore(build): Dodge race condition so manual doesn't build before mod…
alerque Nov 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading