Git Product home page Git Product logo

prefab's Introduction

Prefab

Prefab is a tool for generating build system integrations for prebuilt C/C++ libraries. A Prefab package consists of a small amount of metadata and the prebuilt libraries it describes. Prefab is:

  • Build system agnostic. Build system support is provided via a plugin API, so it's simple to provide support for any build system not supported out of the box.

  • Cross-platform capable. Prefab currently handles only Android libraries, but is designed to handle any number of platforms.

  • Distribution agnostic. Prefab is only an archive format, and can be distributed with whatever package management infrastructure best fits your use case. Android packages will commonly be distributed within an AAR via Maven to be easily used in an Android Gradle project, but distribution as a tarball or a git submodule would work just as well.

Building the command line executable

From the prefab directory run ./gradlew installDist. This will build and install the CLI binary (named prefab) into cli/build/install/prefab/bin/prefab.

prefab's People

Contributors

danalbert avatar dturner avatar prashanthswami avatar rpavlik avatar vaage avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prefab's Issues

[FR] metadata improvements

  1. export_libraries could be optional (actually the whole module.json could be optional).
  2. abi.json could contain an optional 'link' to the binary (relative to the AAR root). This way, a conventional AAR could be reused for prefab by adding a fixed prefab tree. That would be as easy as building a prefab tree structure under src/main/resources of a library module.

Well, include files may require special effort to be in sync with the source tree, but there are some tricks that make this easy on Android Studio.

[DOC] Example on Supporting Custom Archives on Local

Hi @DanAlbert . Thank you for such a great library. Just wondering is there an example on how to use a custom build aar file. I have creating my own aar file in the same manner as this project. However when I import the library in android it fails.

.m2/repository/com/vcpkg/ndk/support/jsoncpp/1.9.2/jsoncpp-1.9.2.pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.vcpkg.ndk.support</groupId>
    <artifactId>jsoncpp</artifactId>
    <version>1.9.2</version>
    <packaging>aar</packaging>
    <description>The Vcpkg AAR for jsoncpp</description>
    <url>https://github.com/microsoft/vcpkg.git</url>

    <dependencies>
    </dependencies>
</project>

The following is the file renamed to zip to allow uploading to GitHub
jsoncpp-1.9.2.zip

[BUG] CLI fails with cryptic error message

Describe the bug
The CLI fails when encountering an invalid artifact i.e. an incorrectly named file under: modules/<library_name>/libs/, however, the error output is sufficiently cryptic to make debugging difficult.

To Reproduce

  • On a Mac create the prefab package folder structure as described here: https://google.github.io/prefab/#package-structure

  • Wait for Mac OS to populate the newly created folders with .DS_Store files

  • Execute the CLI e.g.

    ./cli --build-system cmake --platform android --os-version 21 --stl c++_static --ndk-version 21 --abi x86 --output ~/Code/workspace-android/oboe-prefab/output ~/Code/workspace-android/oboe-prefab

Expected behavior
Error output includes the filename of the invalid artifact folder

Actual behavior
Exception in thread "main" com.google.prefab.api.UnsupportedPlatformException: //oboe/oboe contains artifacts for unsupported platform "" at com.google.prefab.api.Module.<init>(Module.kt:115) at com.google.prefab.api.Package.<init>(Package.kt:77) at com.google.prefab.cli.Cli$packages$2.invoke(Cli.kt:125) at com.google.prefab.cli.Cli$packages$2.invoke(Cli.kt:96) at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) at com.google.prefab.cli.Cli.getPackages(Cli.kt) at com.google.prefab.cli.Cli.validate(Cli.kt:173) at com.google.prefab.cli.Cli.run(Cli.kt:190) at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:139) at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:14) at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:216) at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:213) at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:231) at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:250) at com.google.prefab.cli.AppKt.main(App.kt:29)

Environment:
Prefab version: v1.0.0-alpha5

Host OS:

  • Linux
  • [X ] macOS
  • Windows

[FR] perform best match of available libraries if there are multiple compatible

It's possible for more than one library to be a compatible match, and we currently just select the first match. We can do better in a few ways:

  1. If the libraries differ only by their OS version, use the highest compatible version (i.e. if there's an android-16 and an android-21 library and the user is targeting 21+, prefer the android-21 library).
  2. If the libraries differ only by their NDK version, use the version that best matches the user's NDK version (if there isn't an exact match, I'm not sure whether we should prefer closest older or closest newer...)

If the libraries differ by both of those criteria we'll need to decide a precedence order. I think the order above is probably best, but I haven't given it much thought yet.

[BUG] Prefab errors are not surfaced to Android Studio build log

Describe the bug
If prefab encounters an error during a build it is not surfaced to the user in the Android Studio build log.

To Reproduce

  • Clone the curl-ssl repo
  • Open app/build.gradle and comment out the following line:
    arguments "-DANDROID_STL=c++_shared"
  • Run gradle sync

Expected behavior
Build fails with a clear description of why it failed

Actual behavior
Build fails with the following message:

executing external native build for cmake /Users/donturner/Code/workspace-android/ndk-samples/prefab/curl-ssl/app/src/main/cpp/CMakeLists.txt
Affected Modules: app

Environment:
Prefab version: (if not using the latest, please try the latest first)

Host OS:

  • Linux
  • [ x] macOS
  • Windows

Target platform:
Target ABI:
Target OS version:
Build system:

Additional context
It is possible to view the prefab output by opening the gradle tab then executing the curl-ssl > Tasks > build > build task. Not particularly easy to find.

[FR] nice to have: the cli to accept AAR file

Describe the solution you'd like
I believe that most work is done with AAR packages. It would be nice if prefab command could transparently work with such archives, not expecting the user to extract the AAR manually.

Describe alternatives you've considered
I am afraid that manual extraction of the AAR may cause or hide some problems with some packages.

[FR] ability to specify additive platform-specific headers rather than replacements

Platform-specific headers currently are used as a complete replacement for the module headers. Some libraries have a set of common headers and a set of platform-specific headers (ffmpeg, as an example: #71).

Adding an additive_platform_headers: true option to module.json or possibly an alternative directory name to the library directory would solve this.

[FR] emit cmake packages to the arch-specific directory?

We currently emit the config file directly to the output directory. CMake's docs indicate that it will look in other places as well (https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure), one of which is architecture specific which would make it easier to share the output directory among multi-arch builds.

I'd tried this first, but CMake didn't appear to be searching those other directories. Should spend some more time trying to figure out why.

[FR] per-platform includes?

We don't currently support libraries that need to expose different headers for each platform or subplatform. Adding an optional include directory inside the library directory might be helpful for some libraries. I haven't encountered any yet, but it's possible.

[FR] support for packaging sources for debugging

We may be able to support source debugging of distributed binaries if we package the sources (and possibly separate debug info files, depending on the platform) alongside the binaries in a predictable manner.

[FR] package-wide include directory

Some packages (ffmpeg, openssl) don't split up their headers by library and instead have one common include directory for all of their libraries. For these cases it would be nice to use a package-wide include directory rather than duplicating the headers into every module.

[BUG] bad error message when libs directory has libraries, just not the one it expects

$ prefab --platform android --abi armeabi-v7a --os-version 21 --stl c++_shared --ndk-version 21 --output ffmpeg-out --build-system cmake ffmpeg/prefab 
Exception in thread "main" java.lang.RuntimeException: Prebuilt directory contains no library artifacts: ffmpeg/prefab/modules/ffmpeg/libs/android.x86
        at com.google.prefab.api.ElfKt.findElfLibrary(Elf.kt:44)
        at com.google.prefab.api.Android.libraryFileFromDirectory(Android.kt:351)
        at com.google.prefab.api.PrebuiltLibrary.<init>(PrebuiltLibrary.kt:48)
        at com.google.prefab.api.Module.<init>(Module.kt:158)
        at com.google.prefab.api.Package.<init>(Package.kt:77)
        at com.google.prefab.cli.Cli$packages$2.invoke(Cli.kt:125)
        at com.google.prefab.cli.Cli$packages$2.invoke(Cli.kt:96)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at com.google.prefab.cli.Cli.getPackages(Cli.kt)
        at com.google.prefab.cli.Cli.validate(Cli.kt:173)
        at com.google.prefab.cli.Cli.run(Cli.kt:190)
        at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:139)
        at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:14)
        at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:216)
        at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:213)
        at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:231)
        at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:250)
        at com.google.prefab.cli.AppKt.main(App.kt:29)
$ ls ffmpeg/prefab/modules/ffmpeg/libs/android.x86
abi.json  include  libavcodec.so  libavdevice.so  libavfilter.so  libavformat.so libavutil.so libswresample.so  libswscale.so

The problem is actually that no library match libffmpeg.so or libffmpeg.a was found, but that's very unclear from the error message. This should print:

"Prebuilt directory $directory did not contain the expected library artifacts. Tried $name.a and $name.so."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.