Skip to content

Allow extra C++ flags and include dirs via the environment - #8

Merged
khvzak merged 1 commit into
mlua-rs:mainfrom
chipsenkbeil:env-flags
Aug 29, 2026
Merged

khvzak merged 1 commit into
mlua-rs:mainfrom
chipsenkbeil:env-flags

Conversation

@chipsenkbeil

@chipsenkbeil chipsenkbeil commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Hey there! Long time no chat, I've picked back up using mlua as part of porting a game I was working on from being written entirely in Lua on top of Love2D to instead be a hand-written Rust project that provides modding capabilities via mlua.

My challenge is that the game needs to be deterministic including user-created mods written in Lua. I've managed to handle most determinism by shadowing math.*, but operators like ^ and ^= can't be shadowed in the same way. To solve this, I have to force-include a header that redirects the libm functions IEEE 754 leaves unspecified to my own implementations, which catches ^ and ^= at runtime. The problem is there's no way to pass a compiler flag, so this opens that up for me.

AI helped me figure this out, as a heads up. To my understanding, I just need to read LUAU_CXXFLAGS (whitespace separated) and LUAU_INCLUDE_DIRS (path separated), and declare both with rerun-if-env-changed so changing them forces a rebuild rather than silently reusing an artifact compiled with the old settings.

Also, for clarity, I made this PR even though cc already picks up CXXFLAGS because nothing declares cargo:rerun-if-env-changed for it, so changing the value doesn't trigger a rebuild, which means you silently get an artifact compiled with the old flags while the build reports success.

The vendored Luau sources are compiled by this crate on behalf of
mlua-sys, so a consumer several levels up has no way to influence the
build. Projects needing a compiler flag for correctness rather than
taste currently have to vendor the whole crate to get one in.

Read LUAU_CXXFLAGS (whitespace separated) and LUAU_INCLUDE_DIRS (path
separated), and declare both with rerun-if-env-changed so changing them
forces a rebuild rather than silently reusing an artifact compiled with
the old settings.

The motivating case is a deterministic simulation: it needs
-ffp-contract=off so the modulo expansion cannot fuse into a
multiply-add on some architectures and not others, and a force-included
header redirecting the libm functions IEEE 754 leaves unspecified.
@khvzak
khvzak merged commit 2357280 into mlua-rs:main Aug 29, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants