xmake icon indicating copy to clipboard operation
xmake copied to clipboard

Third-party package shared libraries will not be packed into application bundle when `xcode.application` rule is applied.

Open JX-Master opened this issue 11 months ago • 1 comments

Xmake Version

2.9.8

Operating System Version and Architecture

macOS Sequoia 15.3.2, arm64 (Apple M4 Pro)

Describe Bug

When importing third-party packages to one target using add_packages, if the package has shared libraries (.dylib on macOS and iOS), such shared libraries will be installed as expected when running xmake install, but they will not be copied to the generated application bundle (.app), causing the application failed to launch.

For example, if we have the following xmake file that imports SDL3 for a GUI application:

add_requires("libsdl3", {configs = {shared = true}})

target("SDLTest")
    set_kind("binary")
    add_files("main.cpp")
    add_packages("libsdl3")
target_end()

and we have the following code in main.cpp, which is copied from SDL3 examples:

/*
 * This example code $WHAT_IT_DOES.
 *
 * This code is public domain. Feel free to use it for any purpose!
 */

 #define SDL_MAIN_USE_CALLBACKS 1  /* use the callbacks instead of main() */
 #include <SDL3/SDL.h>
 #include <SDL3/SDL_main.h>
 
 /* We will use this renderer to draw into this window every frame. */
 static SDL_Window *window = NULL;
 static SDL_Renderer *renderer = NULL;
 
 
 /* This function runs once at startup. */
 SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
 {
     SDL_SetAppMetadata("Example HUMAN READABLE NAME", "1.0", "com.example.CATEGORY-NAME");
 
     if (!SDL_Init(SDL_INIT_VIDEO)) {
         SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
         return SDL_APP_FAILURE;
     }
 
     if (!SDL_CreateWindowAndRenderer("examples/CATEGORY/NAME", 640, 480, 0, &window, &renderer)) {
         SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
         return SDL_APP_FAILURE;
     }
     return SDL_APP_CONTINUE;  /* carry on with the program! */
 }
 
 /* This function runs when a new event (mouse input, keypresses, etc) occurs. */
 SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
 {
     if (event->type == SDL_EVENT_QUIT) {
         return SDL_APP_SUCCESS;  /* end the program, reporting success to the OS. */
     }
     return SDL_APP_CONTINUE;  /* carry on with the program! */
 }
 
 /* This function runs once per frame, and is the heart of the program. */
 SDL_AppResult SDL_AppIterate(void *appstate)
 {
     return SDL_APP_CONTINUE;  /* carry on with the program! */
 }
 
 /* This function runs once at shutdown. */
 void SDL_AppQuit(void *appstate, SDL_AppResult result)
 {
     /* SDL will clean up the window/renderer for us. */
 }

Performing xmake install will install the following files, which works as expected:

Image

But if we add add_rules("xcode.application") to xmake.lua like so:

add_requires("libsdl3", {configs = {shared = true}})

target("SDLTest")
    set_kind("binary")
    add_rules("xcode.application")
    add_files("main.cpp")
    add_packages("libsdl3")
target_end()

Then the generated application bundle will only have the target binary, not the third-party libraries (which is libSDL3.0.dylib in our case):

Image

Expected Behavior

When generating application bundles, third-party packages' shared libraries should also be copied to Frameworks directory, just like target files.

Project Configuration

add_requires("libsdl3", {configs = {shared = true}})

target("SDLTest")
    set_kind("binary")
    add_rules("xcode.application")
    add_files("main.cpp")
    add_packages("libsdl3")
target_end()

Additional Information and Error Logs

After checking source code in rules/xcode/applicatiom/build.lua, I found the code that copies library files only handles target library files:

Image

perhaps that is the reason of this bug.

JX-Master avatar Mar 29 '25 03:03 JX-Master

Currently it is not supported, only static library packages are supported.

waruqi avatar Mar 29 '25 13:03 waruqi