Skip to content

[FR] [QUESTION] How to model optional dependencies? #160

Description

@madebr

Is your feature request related to a problem? Please describe.

My application is able to dynamically load dependencies using dlopen + dladdr.
I have modeled every library using prefab json files.

But I don't know of any way, other then explicitly do target_link_libraries to add a dynamic dependency to the .apk.

Describe the solution you'd like

I have 2 suggestions:

  1. add every dependency of the target to the .apk.
    Doing add_dependencies(myexecutable dynamic_dependency), should add dynamic_dependency to the .apk as well
  2. add some function to the android cmake toolchain script that marks a target to be added to the .apk:
    add_target_to_apk(dynamic_dependency)

Describe alternatives you've considered

Right now, I'm simply doing

target_link_libraries(mygame PRIVATE dynamic_dependency)

This type of dependency is honored by android's cmake support,
but should not be necessary.

Additional context

I have encountered this issue while creating a prefab aar for SDL_image.
SDL_image provides decoders for various image formats.
Because not every applications needs every decoder, these are dynamically loaded.
Dynamically loading also reduces the file size of an .apk.

Activity

  1. DanAlbert commented on Oct 11, 2022

    @DanAlbert
    Contributor

    Depending on your answer to #159, I think these two are probably the same FR (modeling for runtime-only dependencies).

  2. DanAlbert commented on Oct 11, 2022

    @DanAlbert
    Contributor

    Duplicate of #159

  3. madebr commented on Oct 11, 2022

    @madebr
    Author

    This is also a run-time dependency, but should only be satisfied when the application really needs it.

    e.g.
    my game needs png support, so needs libpng. But my application does not need tiff support, so does not need libtiff.
    So I would like some way to make sure libpng is bundled in the .apk and not libtiff.

  4. DanAlbert commented on Oct 11, 2022

    @DanAlbert
    Contributor

    Oh, and that choice is made at build time?

  5. DanAlbert commented on Oct 11, 2022

    @DanAlbert
    Contributor

    Okay, I think not strictly a dup then, just closely related. Will reopen to track the optional aspect of runtime dependencies.

  6. madebr commented on Oct 11, 2022

    @madebr
    Author

    Oh, and that choice is made at build time?

    Yes, the library must be included at build time.

    #159 is a dependency that can be modeled in json files to be processed by prefab.
    The dependency here is made in the cmake script.

    I'm not 100% sure this is a prefab issue though.
    If it isn't, can you please show me where to go instead or what alternatives there are?

  7. DanAlbert commented on Oct 11, 2022

    @DanAlbert
    Contributor

    I haven't thought about it very deeply yet, but I suspect prefab needs to be at least somewhat involved here, if only to pass along metadata to another system like AGP.

    How do you envision this being controlled by the consumer? I think this probably ends up being something system-specific in your build script. For CMake this is probably something like https://cmake.org/cmake/help/latest/command/install.html#installing-runtime-dependencies?

    install(RUNTIME_DEPENDENCY_SET package::optional-dependency)

    install seems to be how CMakes wants runtime dependencies declared. AGP doesn't currently use that model (it probably should have). We've considered adding support for that before, and this may require it.

    ndk-build would need to grow a similar feature, but that's fairly easy.

    Or did you have something else in mind? The other things I can think of would be something contained in the build.gradle file, which seems like it'd be cumbersome for the author to keep in sync with the real build script; or doubling up on packaging some modules so it would expose both package::module and package::module-with-optional-dependency, which works today but is prone to combinatoric explosion for something like ffmpeg...

  8. changed the title [-][FR] [QUESTION] How to model a dynamic dependency?[/-] [+][FR] [QUESTION] How to model optional dependencies?[/+] on Oct 11, 2022
  9. added this to Prefab 2.2.0 and removed this from Prefab 2.1.0on Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions