JX-Master / LunaSDK

Luna SDK is a C++ software development framework for real-time rendering applications.
Other
124 stars 8 forks source link

Change module system API #61

Closed JX-Master closed 10 months ago

JX-Master commented 10 months ago

The old module system uses static variables to register modules automatically when the library file is loaded. However, the linker may omit the object file that includes the static variable if no symbols in the same file are used by other codes, causing such modules not added to the module system. If we're building shared libraries, we can define one dummy function in the same CPP file that defines the module static variable, and use -u linker flag to force the linker to include that function symbol, thus includes other variable. But when we are building static libraries, this becomes infeasible because the linking happens only when build the final executable files, and it is tricky to use -u to specify all possibly used modules in the executable file building scripts. Furthermore, if we are importing LunaSDK as one xmake package, it is impossible to specify -u for LunaSDK libraries, since we can only specify add_packages to link against LunaSDK. This merge replaces the old module system with a new one, which requires the user to specify all modules directly used by the application before calling init_modules. When one module is registered to the module system, it has a change to register all its dependency modules to the module system as well. Since now every module variable is registered to the module system explicitly, we no longer need linker tricks to include our static variables, and the module registration and initialization happens just like what we expected.