Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ __pycache__/
!triplets/community/x86-windows-static.cmake
!triplets/community/x86-windows-static-md.cmake
!triplets/community/x64-osx-dynamic.cmake
!triplets/community/x64-android.cmake
!triplets/community/x86-android.cmake
!triplets/community/arm-android.cmake
!triplets/community/arm64-android.cmake
!triplets/arm-uwp.cmake
!triplets/x64-uwp.cmake
!triplets/x64-windows.cmake
Expand All @@ -320,3 +324,5 @@ __pycache__/
# vcpkg - End
############################################################
archives
.DS_Store
prefab/
124 changes: 124 additions & 0 deletions docs/specifications/prefab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
## Exporting to Android Archives (AAR files)

Vcpkg current supports exporting to android archive files([AAR files](https://developer.android.com/studio/projects/android-library)). Once the archive is created it can imported in Android Studio as a native dependent. The archive is automatically consumed using [android studio's prefab tool](https://github.com/google/prefab). For more information on Prefab checkout the following article ["Native Dependencies in Android Studio 4.0"](https://android-developers.googleblog.com/2020/02/native-dependencies-in-android-studio-40.html) and the documentation on how to use prefab on [https://google.github.io/prefab/](https://google.github.io/prefab).

#### To support export to android the following tools should be available;

- `maven <optional>`
- `ndk <required>`
- `7zip <required on windows>` or `zip <required on linux>`

**Android triplets that support the following architectures arm64-v8a, armeabi-v7a, x86_64 x86 must be present**

#### An example of a triplet configuration targeting android would be

```cmake
set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
```

The following table outlines the mapping from vcpkg architectures to android architectures

|vcpkg architecture | android architecture |
|-------------------|----------------------|
|arm64 | arm64-v8a |
|arm | armeabi-v7a |
|x64 | x86_64 |
|x86 | x86 |

**Please note the four architectures are required. If any is missing the export will fail**
**To export the following environment `ANDROID_NDK_HOME` variable is required for exporting**

#### Example exporting [jsoncpp]
The `--prefab-maven` flag is option. Only call it when you have maven installed
```
./vcpkg export --triplet x64-android jsoncpp --prefab --prefab-maven
```

```
The following packages are already built and will be exported:
jsoncpp:x86-android
Exporting package jsoncpp...
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
[INFO] Installing<root>/prefab/jsoncpp/jsoncpp-1.9.2.aar to /.m2/repository/com/vcpkg/ndk/support/jsoncpp/1.9.2/jsoncpp-1.9.2.aar
[INFO] Installing <vcpkg_root>/prefab/jsoncpp/pom.xml to /.m2/repository/com/vcpkg/ndk/support/jsoncpp/1.9.2/jsoncpp-1.9.2.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.301 s
[INFO] Finished at: 2020-03-01T10:18:15Z
[INFO] ------------------------------------------------------------------------
In app/build.gradle

com.vcpkg.ndk.support:jsoncpp:1.9.2

And cmake flags

externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_shared'
cppFlags "-std=c++17"
}
}

In gradle.properties

android.enablePrefab=true
android.enableParallelJsonGen=false
android.prefabVersion=${prefab.version}

Successfuly exported jsoncpp. Checkout <vcpkg_root>/prefab/jsoncpp/aar
```

#### The output directory after export
```
prefab
└── jsoncpp
├── aar
│   ├── AndroidManifest.xml
│   ├── META-INF
│   │   └── LICENCE
│   └── prefab
│   ├── modules
│   │   └── jsoncpp
│   │   ├── include
│   │   │   └── json
│   │   │   ├── allocator.h
│   │   │   ├── assertions.h
│   │   │   ├── autolink.h
│   │   │   ├── config.h
│   │   │   ├── forwards.h
│   │   │   ├── json.h
│   │   │   ├── json_features.h
│   │   │   ├── reader.h
│   │   │   ├── value.h
│   │   │   ├── version.h
│   │   │   └── writer.h
│   │   ├── libs
│   │   │   ├── android.arm64-v8a
│   │   │   │   ├── abi.json
│   │   │   │   └── libjsoncpp.so
│   │   │   ├── android.armeabi-v7a
│   │   │   │   ├── abi.json
│   │   │   │   └── libjsoncpp.so
│   │   │   ├── android.x86
│   │   │   │   ├── abi.json
│   │   │   │   └── libjsoncpp.so
│   │   │   └── android.x86_64
│   │   │   ├── abi.json
│   │   │   └── libjsoncpp.so
│   │   └── module.json
│   └── prefab.json
├── jsoncpp-1.9.2.aar
└── pom.xml

13 directories, 25 files
```
82 changes: 82 additions & 0 deletions toolsrc/include/vcpkg/export.prefab.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#pragma once

#include <vcpkg/base/system.h>
#include <vcpkg/dependencies.h>
#include <vcpkg/vcpkgpaths.h>


#include <vector>

namespace vcpkg::Export::Prefab
{
constexpr int kFragmentSize = 3;

struct Options
{
Optional<std::string> maybe_group_id;
Optional<std::string> maybe_artifact_id;
Optional<std::string> maybe_version;
Optional<std::string> maybe_min_sdk;
Optional<std::string> maybe_target_sdk;
bool enable_maven;
bool enable_debug;
};
struct NdkVersion
{
NdkVersion(int _major, int _minor, int _patch) : m_major{_major},
m_minor{_minor},
m_patch{_patch}{
}
int major() { return this->m_major; }
int minor() { return this->m_minor; }
int patch() { return this->m_patch; }
std::string to_string();
void to_string(std::string& out);

private:
int m_major;
int m_minor;
int m_patch;
};

struct ABIMetadata
{
std::string abi;
int api;
int ndk;
std::string stl;
std::string to_string();
};

struct PlatformModuleMetadata
{
std::vector<std::string> export_libraries;
std::string library_name;
std::string to_json();
};

struct ModuleMetadata
{
std::vector<std::string> export_libraries;
std::string library_name;
PlatformModuleMetadata android;
std::string to_json();
};

struct PackageMetadata
{
std::string name;
int schema;
std::vector<std::string> dependencies;
std::string version;
std::string to_json();
};



void do_export(const std::vector<Dependencies::ExportPlanAction>& export_plan,
const VcpkgPaths& paths,
const Options& prefab_options, const Triplet& triplet);
Optional<std::string> find_ndk_version(const std::string &content);
Optional<NdkVersion> to_version(const std::string &version);
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/triplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ namespace vcpkg
static const Triplet X64_UWP;
static const Triplet ARM_UWP;
static const Triplet ARM64_UWP;

static const Triplet ARM_ANDROID;
static const Triplet ARM64_ANDROID;
static const Triplet X86_ANDROID;
static const Triplet X64_ANDROID;

const std::string& canonical_name() const;
const std::string& to_string() const;
Expand Down
2 changes: 2 additions & 0 deletions toolsrc/include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace vcpkg
namespace Tools
{
static const std::string SEVEN_ZIP = "7zip";
static const std::string SEVEN_ZIP_ALT = "7z";
static const std::string MAVEN = "mvn";
static const std::string CMAKE = "cmake";
static const std::string GIT = "git";
static const std::string NINJA = "ninja";
Expand Down
51 changes: 46 additions & 5 deletions toolsrc/src/vcpkg/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vcpkg/commands.h>
#include <vcpkg/dependencies.h>
#include <vcpkg/export.chocolatey.h>
#include <vcpkg/export.prefab.h>
#include <vcpkg/export.h>
#include <vcpkg/export.ifw.h>
#include <vcpkg/help.h>
Expand Down Expand Up @@ -196,6 +197,7 @@ namespace vcpkg::Export
{
constexpr const ArchiveFormat ZIP(ArchiveFormat::BackingEnum::ZIP, "zip", "zip");
constexpr const ArchiveFormat SEVEN_ZIP(ArchiveFormat::BackingEnum::SEVEN_ZIP, "7z", "7zip");
constexpr const ArchiveFormat AAR(ArchiveFormat::BackingEnum::ZIP, "aar", "zip");
}

static fs::path do_archive_export(const VcpkgPaths& paths,
Expand Down Expand Up @@ -263,6 +265,7 @@ namespace vcpkg::Export
bool zip = false;
bool seven_zip = false;
bool chocolatey = false;
bool prefab = false;
bool all_installed = false;

Optional<std::string> maybe_output;
Expand All @@ -271,6 +274,7 @@ namespace vcpkg::Export
Optional<std::string> maybe_nuget_version;

IFW::Options ifw_options;
Prefab::Options prefab_options;
Chocolatey::Options chocolatey_options;
std::vector<PackageSpec> specs;
};
Expand All @@ -293,19 +297,34 @@ namespace vcpkg::Export
static constexpr StringLiteral OPTION_CHOCOLATEY_MAINTAINER = "--x-maintainer";
static constexpr StringLiteral OPTION_CHOCOLATEY_VERSION_SUFFIX = "--x-version-suffix";
static constexpr StringLiteral OPTION_ALL_INSTALLED = "--x-all-installed";

static constexpr StringLiteral OPTION_PREFAB = "--prefab";
static constexpr StringLiteral OPTION_PREFAB_GROUP_ID = "--prefab-group-id";
static constexpr StringLiteral OPTION_PREFAB_ARTIFACT_ID = "--prefab-artifact-id";
static constexpr StringLiteral OPTION_PREFAB_VERSION = "--prefab-version";
static constexpr StringLiteral OPTION_PREFAB_SDK_MIN_VERSION = "--prefab-min-sdk";
static constexpr StringLiteral OPTION_PREFAB_SDK_TARGET_VERSION = "--prefab-target-sdk";
static constexpr StringLiteral OPTION_PREFAB_ENABLE_MAVEN = "--prefab-maven";
static constexpr StringLiteral OPTION_PREFAB_ENABLE_DEBUG = "--prefab-debug";


static constexpr std::array<CommandSwitch, 8> EXPORT_SWITCHES = {{


static constexpr std::array<CommandSwitch, 11> EXPORT_SWITCHES = {{
{OPTION_DRY_RUN, "Do not actually export"},
{OPTION_RAW, "Export to an uncompressed directory"},
{OPTION_NUGET, "Export a NuGet package"},
{OPTION_IFW, "Export to an IFW-based installer"},
{OPTION_ZIP, "Export to a zip file"},
{OPTION_SEVEN_ZIP, "Export to a 7zip (.7z) file"},
{OPTION_CHOCOLATEY, "Export a Chocolatey package (experimental feature)"},
{OPTION_PREFAB, "Export to Prefab format"},
{OPTION_PREFAB_ENABLE_MAVEN, "Enable maven"},
{OPTION_PREFAB_ENABLE_DEBUG, "Enable prefab debug"},
{OPTION_ALL_INSTALLED, "Export all installed packages"},
}};

static constexpr std::array<CommandSetting, 10> EXPORT_SETTINGS = {{
static constexpr std::array<CommandSetting, 15> EXPORT_SETTINGS = {{
{OPTION_OUTPUT, "Specify the output name (used to construct filename)"},
{OPTION_NUGET_ID, "Specify the id for the exported NuGet package (overrides --output)"},
{OPTION_NUGET_VERSION, "Specify the version for the exported NuGet package"},
Expand All @@ -318,6 +337,11 @@ namespace vcpkg::Export
"Specify the maintainer for the exported Chocolatey package (experimental feature)"},
{OPTION_CHOCOLATEY_VERSION_SUFFIX,
"Specify the version suffix to add for the exported Chocolatey package (experimental feature)"},
{OPTION_PREFAB_GROUP_ID, "GroupId uniquely identifies your project according maven specifications"},
{OPTION_PREFAB_ARTIFACT_ID, "Artifact Id is the name of the project according maven specifications"},
{OPTION_PREFAB_VERSION, "Version is the name of the project according maven specifications"},
{OPTION_PREFAB_SDK_MIN_VERSION, "Android minimum supported sdk version"},
{OPTION_PREFAB_SDK_TARGET_VERSION, "Android target sdk version"},
}};

const CommandStructure COMMAND_STRUCTURE = {
Expand All @@ -343,8 +367,11 @@ namespace vcpkg::Export
ret.zip = options.switches.find(OPTION_ZIP) != options.switches.cend();
ret.seven_zip = options.switches.find(OPTION_SEVEN_ZIP) != options.switches.cend();
ret.chocolatey = options.switches.find(OPTION_CHOCOLATEY) != options.switches.cend();
ret.all_installed = options.switches.find(OPTION_ALL_INSTALLED) != options.switches.end();
ret.prefab = options.switches.find(OPTION_PREFAB) != options.switches.cend();
ret.prefab_options.enable_maven = options.switches.find(OPTION_PREFAB_ENABLE_MAVEN) != options.switches.cend();
ret.prefab_options.enable_debug = options.switches.find(OPTION_PREFAB_ENABLE_DEBUG) != options.switches.cend();
ret.maybe_output = maybe_lookup(options.settings, OPTION_OUTPUT);
ret.all_installed = options.switches.find(OPTION_ALL_INSTALLED) != options.switches.end();

if (ret.all_installed)
{
Expand All @@ -363,10 +390,10 @@ namespace vcpkg::Export
});
}

if (!ret.raw && !ret.nuget && !ret.ifw && !ret.zip && !ret.seven_zip && !ret.dry_run && !ret.chocolatey)
if (!ret.raw && !ret.nuget && !ret.ifw && !ret.zip && !ret.seven_zip && !ret.dry_run && !ret.chocolatey && !ret.prefab)
{
System::print2(System::Color::error,
"Must provide at least one export type: --raw --nuget --ifw --zip --7zip --chocolatey\n");
"Must provide at least one export type: --raw --nuget --ifw --zip --7zip --chocolatey --prefab\n");
System::print2(COMMAND_STRUCTURE.example_text);
Checks::exit_fail(VCPKG_LINE_INFO);
}
Expand Down Expand Up @@ -417,6 +444,16 @@ namespace vcpkg::Export
{OPTION_IFW_CONFIG_FILE_PATH, ret.ifw_options.maybe_config_file_path},
{OPTION_IFW_INSTALLER_FILE_PATH, ret.ifw_options.maybe_installer_file_path},
});

options_implies(OPTION_PREFAB,
ret.prefab,
{
{OPTION_PREFAB_ARTIFACT_ID, ret.prefab_options.maybe_artifact_id},
{OPTION_PREFAB_GROUP_ID, ret.prefab_options.maybe_group_id},
{OPTION_PREFAB_SDK_MIN_VERSION, ret.prefab_options.maybe_min_sdk},
{OPTION_PREFAB_SDK_TARGET_VERSION, ret.prefab_options.maybe_target_sdk},
{OPTION_PREFAB_VERSION, ret.prefab_options.maybe_version},
});

options_implies(OPTION_CHOCOLATEY,
ret.chocolatey,
Expand Down Expand Up @@ -605,6 +642,10 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
Chocolatey::do_export(export_plan, paths, opts.chocolatey_options);
}

if(opts.prefab){
Prefab::do_export(export_plan, paths, opts.prefab_options, default_triplet);
}

Checks::exit_success(VCPKG_LINE_INFO);
}
}
Loading