Skip to content

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

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.

3 participants