Skip to content

Add cmake setting to build as dll#1741

Closed
TheGreatSageEqualToHeaven wants to merge 2 commits intoluau-lang:masterfrom
rce-incorporated:master
Closed

Add cmake setting to build as dll#1741
TheGreatSageEqualToHeaven wants to merge 2 commits intoluau-lang:masterfrom
rce-incorporated:master

Conversation

@TheGreatSageEqualToHeaven
Copy link
Contributor

Adds LUAU_EXPORT_DLL to CMakeLists.txt.

@Mooshua
Copy link

Mooshua commented Mar 24, 2025

This doesn't really work in practice, and shared linking to the Analysis target will require a little more spice.

In my build setup I compile lapi (plus other files that implement the core api), lcodegen, and lcode into a shared library, and then privately link that with the VM, Compiler, and CodeGen targets. On MSVC (with some added tuning of compiler flags) this builds into a little over 700kb.

add_subdirectory(pkg/luau)

add_library(Luau.Shared SHARED
    pkg/luau/VM/src/lapi.cpp
    pkg/luau/VM/src/laux.cpp
    pkg/luau/VM/src/lstate.cpp
    pkg/luau/VM/src/linit.cpp
    pkg/luau/VM/src/ldo.cpp
    pkg/luau/VM/src/lbaselib.cpp
    pkg/luau/VM/src/lvmload.cpp

    pkg/luau/CodeGen/src/lcodegen.cpp
    pkg/luau/Compiler/src/lcode.cpp
)
target_link_libraries(Luau.Shared PRIVATE Luau.VM Luau.Compiler Luau.CodeGen)
target_link_libraries(Luau.Shared PUBLIC Luau.Common Luau.Ast)

IF (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
    target_compile_definitions(Luau.Shared PRIVATE "LUA_API=__declspec(dllexport)")
    target_compile_definitions(Luau.Shared PRIVATE "LUACODE_API=__declspec(dllexport)")
    target_compile_definitions(Luau.Shared PRIVATE "LUACODEGEN_API=__declspec(dllexport)")

    target_compile_definitions(Luau.Shared INTERFACE "LUA_API=__declspec(dllimport)")
    target_compile_definitions(Luau.Shared INTERFACE "LUACODE_API=__declspec(dllimport)")
    target_compile_definitions(Luau.Shared INTERFACE "LUACODEGEN_API=__declspec(dllimport)")
ENDIF()

PS: This uses a local patch to remove the Luau.VM.Internal dependency from lcodegen.cpp. Nothing major, just deleting the lapi.h include.

@aatxe aatxe requested a review from vegorov-rbx March 24, 2025 20:57
@TheGreatSageEqualToHeaven
Copy link
Contributor Author

This doesn't really work in practice, and shared linking to the Analysis target will require a little more spice.

This does work in practice and has worked in practice for the past nearly 4 years, however I only use it purely for linking with C# (without Analysis at all) so perhaps for your cases it wouldn't work.

image

@Mooshua
Copy link

Mooshua commented Mar 26, 2025

This does work in practice and has worked in practice for the past nearly 4 years
@TheGreatSageEqualToHeaven

It doesn't even compile.

@TheGreatSageEqualToHeaven
Copy link
Contributor Author

It doesn't even compile.

image
image
image

+ the existing image of me literally using the dll that I compiled with my changes in my original reply?

@TheGreatSageEqualToHeaven
Copy link
Contributor Author

@vegorov-rbx

@aatxe
Copy link
Member

aatxe commented Jan 23, 2026

The branch itself seems to have been deleted here or GitHub is otherwise having a bad time, but we merged this functionality in #2208.

@aatxe aatxe closed this Jan 23, 2026
@TheGreatSageEqualToHeaven
Copy link
Contributor Author

The branch itself seems to have been deleted here or GitHub is otherwise having a bad time, but we merged this functionality in #2208.

I think I deleted the repository when moving it to our private workflow (which isn't on github) so that we could build it easier, my bad 😆

@aatxe
Copy link
Member

aatxe commented Jan 23, 2026

no worries!

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.

4 participants