This section covers a feature that has been removed from kmpkg. The documentation for this feature is no longer maintained.
Binary caching configuration
Configuration Syntax
Binary caching is configured with the environment variable KMPKG_BINARY_SOURCES (set to <source>;<source>;...) and
the command line option --binarysource=<source>. Options are evaluated
first from the environment, then from the command line. Binary caching can be completely disabled by passing
--binarysource=clear as the last command line option.
| Form | Description |
|---|---|
clear | Disable all previous sources (including the default) |
default[,<rw>] | Adds the default files provider |
files,<absolute path>[,<rw>] | Adds a file-based location |
nuget,<uri>[,<rw>] | Adds a NuGet-based source; equivalent to the -Source parameter of the NuGet CLI |
nugetconfig,<path>[,<rw>] | Adds a NuGet-config-file-based source; equivalent to the -Config parameter of the NuGet CLI. |
nugettimeout,<seconds> | Specifies a timeout for NuGet network operations; equivalent to the -Timeout parameter of the NuGet CLI. |
http,<url_template>[,<rw>[,<header>]] | Adds a custom http-based location. |
x-azblob,<baseuri>,<sas>[,<rw>] | Experimental: will change or be removed without warning Adds an Azure Blob Storage source using a Shared Access Signature. |
x-azcopy,<baseuri>,[,<rw>] | Experimental: will change or be removed without warning Adds an Azure Blob Storage. Supports Microsoft Entra ID. Uses the AzCopy tool. |
x-azcopy-sas,<baseuri>,<sas>[,<rw>] | Experimental: will change or be removed without warning Adds an Azure Blob Storage source using a Shared Access Signature. Uses the AzCopy tool. |
x-gcs,<prefix>[,<rw>] | Experimental: will change or be removed without warning Adds a Google Cloud Storage (GCS) source. |
x-aws,<prefix>[,<rw>] | Experimental: will change or be removed without warning Adds an AWS S3 source. |
x-aws-config,<parameter> | Experimental: will change or be removed without warning Configure all AWS S3 providers. |
x-cos,<prefix>[,<rw>] | Experimental: will change or be removed without warning Adds a Tencent Cloud Object Storage source. |
x-gha,<rw>] | Removed: This feature has been removed from kmpkg |
x-az-universal,<organization>,<project>,<feed>[,<rw>] | Experimental: will change or be removed without warning Use Universal Packages in Azure Artifacts as source. |
interactive | Enables interactive credential management for NuGet (for debugging; requires --debug on the command line) |
The <rw> optional parameter for certain sources controls whether they will be consulted for
downloading binaries (read)(default), whether on-demand builds will be uploaded to that remote
(write), or both (readwrite).
Providers
AWS S3 provider
This section covers an experimental feature of kmpkg which may change or be removed at any time.
x-aws,<prefix>[,<rw>]
Add an AWS S3 source using the AWS CLI. <prefix> should start with s3:// and end in a /.
x-aws-config,no-sign-request
Pass --no-sign-request to the AWS CLI.
Azure Blob Storage provider
This section covers an experimental feature of kmpkg which may change or be removed at any time.
x-azblob,<baseuri>,<sas>[,<rw>]
Adds an Azure Blob Storage provider using Shared Access Signature validation. <baseuri> should include the container path.
Tencent Cloud Object Storage provider
This section covers an experimental feature of kmpkg which may change or be removed at any time.
x-cos,<prefix>[,<rw>]
Adds a COS source. <prefix> should start with cos:// and end with /.
Files provider
files,<absolute path>[,<rw>]
Stores zip-compressed archives at the path based on the binary caching ID.
Google Cloud Storage provider
This section covers an experimental feature of kmpkg which may change or be removed at any time.
x-gcs,<prefix>[,<rw>]
Adds a Google Cloud Storage provider. <prefix> should start with gs:// and end with /.
Quickstart
First, you need to create an Google Cloud Platform Account as well as a storage bucket GCS Quick Start.
As part of this quickstart you would have configured the gsutil command-line tool to authenticate with Google Cloud. kmpkg will use this command-line tool, so make sure it is in your search path for executables.
Example 1 (using a bucket without a common prefix for the objects):
x-gcs,gs://<bucket-name>/,readwrite
Example 2 (using a bucket and a prefix for the objects):
x-gcs,gs://<bucket-name>/my-kmpkg-cache/maybe/with/many/slashes/,readwrite
x-gcs,gs://<bucket-name>/my-kmpkg-cache/maybe/with`,commas/too!/,readwrite
Commas (,) are valid as part of a object prefix in GCS. Remember to escape them in the kmpkg configuration, as shown in the previous example. GCS does not have folders (some of the GCS tools simulate folders). It is not necessary to create or otherwise manipulate the prefix used by your kmpkg cache.
GitHub Actions cache
This section covers a feature that has been removed from kmpkg. The documentation for this feature is no longer maintained.
Universal Packages in Azure Artifacts
This section covers an experimental feature of kmpkg which may change or be removed at any time.
The
x-az-universalprovider is known to perform slowly with large numbers of binary packages. The kmpkg team recommends using a different backend likex-azcopywhen possible.
x-az-universal,<organization>,<project>,<feed>[,<rw>]
HTTP provider
http,<url_template>[,<rw>[,<header>]]
Each binary caching operation is mapped to an HTTP verb:
- Download -
GET - Upload -
PUT - Check Existence -
HEAD
URL Template
The template uses curly-brackets for variable expansion. You can use the variables 'name', 'version', 'sha' and 'triplet'. For example:
https://cache.example.com/{name}/{version}/{sha}
Header
This value may appear on the command line of external process calls, which may have security implications in your environment.
Authentication is supported by specifying an HTTP Authorization Header. For example:
http,https://cache.example.com/{name}/{version}/{sha},readwrite,Authorization: Bearer BearerTokenValue
NuGet provider
Add a NuGet server with the -Source NuGet CLI parameter:
nuget,<uri>[,<rw>]
Use a NuGet config file with the -Config NuGet CLI parameter:
nugetconfig,<path>[,<rw>]
Configure the timeout for NuGet sources:
nugettimeout,<seconds>
Config files must define a defaultPushSource to support writing packages back to the feed.
Credentials
Many NuGet servers require additional credentials to access. The most flexible way to supply credentials is via the nugetconfig source with a custom nuget.config file. See Consuming packages from authenticated feeds for more information.
However, it is still possible to authenticate against many servers using NuGet's built-in credential providers or via customizing your environment's default nuget.config. The default config can be extended via nuget client calls such as:
nuget sources add -Name MyRemote -Source https://... -Username $user -Password $pass
and then passed to kmpkg via nuget,MyRemote,readwrite. You can get a path to the precise copy of NuGet used by kmpkg by running kmpkg fetch nuget, which will report something like:
$ kmpkg fetch nuget
/kmpkg/downloads/tools/nuget-5.5.1-linux/nuget.exe
Non-Windows users will need to call this through mono via mono /path/to/nuget.exe sources add ....
metadata.repository
The nuget and nugetconfig source providers respect certain environment variables while generating nuget packages. The metadata.repository field of any packages will be generated as:
<repository type="git" url="${KMPKG_NUGET_REPOSITORY}"/>
or
<repository type="git"
url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
branch="${GITHUB_REF}"
commit="${GITHUB_SHA}"/>
if the appropriate environment variables are defined and non-empty. This is specifically used to associate packages in GitHub Packages with the building project and not intended to associate with the original package sources.
NuGet Cache
NuGet's user-wide cache is not used by default. To use it for every nuget-based
source, set the environment
variable
KMPKG_USE_NUGET_CACHE to true (case-insensitive) or 1.
Provider Examples
If your CI system of choice is not listed, you are welcome to submit a PR to add it!
GitHub Packages
To use kmpkg with GitHub Packages, it is recommended to use the NuGet provider.
2020-09-21: GitHub's hosted agents come with an older, pre-installed copy of kmpkg on the path that does not support the latest binary caching. This means that direct calls to
bootstrap-kmpkgorkmpkgwithout a path prefix may call an unintended kmpkg instance. If you want to use your own copy of kmpkg, the following two steps to avoid issues if you want to use your own copy of kmpkg:
- Run the equivalent of
rm -rf "$KMPKG_INSTALLATION_ROOT"usingshell: 'bash'.- Always call
kmpkgandbootstrap-kmpkgwith a path prefix, such as./kmpkg,kmpkg/kmpkg,.\bootstrap-kmpkg.bat, etc.
# actions.yaml
#
# In this example, kmpkg has been added as a submodule (`git submodule add https://github.com/kumose/kmpkg`).
env:
KMPKG_BINARY_SOURCES: 'clear;nuget,GitHub,readwrite'
matrix:
os: ['windows-2019', 'ubuntu-20.04']
include:
- os: 'windows-2019'
triplet: 'x86-windows'
mono: ''
- os: 'ubuntu-20.04'
triplet: 'x64-linux'
# To run `nuget.exe` on non-Windows platforms, `mono` must be used.
mono: 'mono'
steps:
# This step assumes `kmpkg` has been bootstrapped (run `./kmpkg/bootstrap-kmpkg`)
- name: 'Setup NuGet Credentials'
shell: 'bash'
# Replace <OWNER> with your organization name
run: |
${{ matrix.mono }} `./kmpkg/kmpkg fetch nuget | tail -n 1` \
sources add \
-source "https://nuget.pkg.github.com/<OWNER>/index.json" \
-storepasswordincleartext \
-name "GitHub" \
-username "<OWNER>" \
-password "${{ secrets.GITHUB_TOKEN }}"
${{ matrix.mono }} `./kmpkg/kmpkg fetch nuget | tail -n 1` \
setapikey "${{ secrets.GITHUB_TOKEN }}" \
-source "https://nuget.pkg.github.com/<OWNER>/index.json"
# Omit this step if you're using manifests
- name: 'kmpkg package restore'
shell: 'bash'
run: >
./kmpkg/kmpkg install sqlite3 cpprestsdk --triplet ${{ matrix.triplet }}
If you're using manifests, you can omit the
kmpkg package restore step: it will be run automatically as part of your
build.
See the GitHub Packages' NuGet documentation for more information.
Using the feed from a pipeline
# azure-pipelines.yaml
variables:
- name: KMPKG_BINARY_SOURCES
value: 'clear;nuget,<FEED_URL>,readwrite'
steps:
# Remember to add this task to allow kmpkg to upload archives via NuGet
- task: NuGetAuthenticate@0
If you are using custom agents with a non-Windows OS, you will need to install Mono to run nuget.exe (apt install mono-complete, brew install mono, etc).
Using the feed locally
# On Windows Powershell
PS> & $(kmpkg fetch nuget | select -last 1) sources add `
-name ADO `
-Source https://pkgs.dev.azure.com/$ORG/_packaging/$FEEDNAME/nuget/v3/index.json `
-Username $USERNAME `
-Password $PAT
PS> $env:KMPKG_BINARY_SOURCES="nuget,ADO,readwrite"
# On Linux or OSX
$ mono `kmpkg fetch nuget | tail -n1` sources add \
-name ADO \
-Source https://pkgs.dev.azure.com/$ORG/_packaging/$FEEDNAME/nuget/v3/index.json \
-Username $USERNAME \
-Password $PAT
$ export KMPKG_BINARY_SOURCES="nuget,ADO,readwrite"
Use a Personal Access Token (PAT) as the password for maximum security. You can generate a PAT in User Settings -> Personal Access Tokens or https://dev.azure.com/<ORG>/_usersSettings/tokens.
ABI Hash
Information on the ABI Hash is provided as an implementation note and will change without notice.
For every build, kmpkg calculates an ABI Hash to determine equivalence. If two builds have the same ABI Hash, kmpkg will consider them identical and reuse the binaries across projects and machines.
The ABI Hash considers:
- Every file in the port directory
- The triplet file contents and name
- The C++ compiler executable file
- The C compiler executable file
- The set of features selected
- The ABI Hash of each dependency
- All helper functions referenced by
portfile.cmake(heuristic) - The version of CMake used
- The version of PowerShell used (Windows)
- The contents of any environment variables listed in
KMPKG_ENV_PASSTHROUGH - The toolchain file's textual contents
(
KMPKG_CHAINLOAD_TOOLCHAIN_FILE) - The GRDK toolkit (only when targeting the Xbox platform)
Despite this extensive list, it is possible to defeat the cache and introduce nondeterminism. If you have additional details that you need to track for your environment, you can generate a triplet file with your additional information in a comment. That additional information will be included in the ABI Hash and ensure a unique universe of binaries.
Files named .DS_Store are not considered for the ABI hash.
The calculated ABI Hashes are stored in each package and in the current installed directory at /share/<port>/kmpkg_abi_info.txt for inspection.
Example ABI Hash of zlib
Enable debug output to print the full Application Binary Interface (ABI) hash of a pacakge. For zlib:
[DEBUG] Trying to hash <path>\buildtrees\zlib\x86-windows.kmpkg_abi_info.txt
[DEBUG] <path>\buildtrees\zlib\x86-windows.kmpkg_abi_info.txt has hash bb1c96759ac96102b4b18215db138daedd3eb16c2cd3302ae7bffab2b643eb87
The ABI hash bb1c96759ac96102b4b18215db138daedd3eb16c2cd3302ae7bffab2b643eb87 for package zlib is constructed by hashing all the possible relevant information to distinguish binary packages.
The version of your compiler is part of the ABI hash, and is calculated below:
[DEBUG] -- The C compiler identification is MSVC 19.36.32538.0
[DEBUG] -- The CXX compiler identification is MSVC 19.36.32538.0
[DEBUG] #COMPILER_HASH#f5d02a6542664cfbd4a38db478133cbb1a18f315
Relevant files, compiler and tool version information are hashed to compute the final ABI hash:
[DEBUG] <abientries for zlib:x86-windows>
[DEBUG] 0001-Prevent-invalid-inclusions-when-HAVE_-is-set-to-0.patch|750b9542cb55e6328cca01d3ca997f1373b9530afa95e04213168676936e7bfa
[DEBUG] 0002-skip-building-examples.patch|835ddecfed752e0f49be9b0f8ff7ba76541cb0a150044327316e22ca84f8d0c2
[DEBUG] 0003-build-static-or-shared-not-both.patch|d6026271dcb3d8fc74b41e235620ae31576a798e77aa411c3af8cd9e948c02b1
[DEBUG] 0004-android-and-mingw-fixes.patch|37a43eddbcb1b7dde49e7659ae895dfd0ff1df66666c1371ba7d5bfc49d8b438
[DEBUG] cmake|3.26.2
[DEBUG] features|core
[DEBUG] portfile.cmake|ac63047b644fa758860dd7ba48ff9a13b058c6f240b8e8d675b8fbba035976be
[DEBUG] ports.cmake|5a8e00cedff0c898b1f90f7d129329d0288801bc9056562b039698caf31ff3f3
[DEBUG] post_build_checks|2
[DEBUG] powershell|7.3.6
[DEBUG] triplet|x86-windows
[DEBUG] triplet_abi|3e71dd1d4afa622894ae367adbbb1ecbd42c57c51428a86b675fa1c8cad3a581-36b818778ba6f2c16962495caedb9a7b221d5be4c60de1cd3060f549319a9931-f5d02a6542664cfbd4a38db478133cbb1a18f315
[DEBUG] usage|be22662327df993eebc437495add75acb365ab18d37c7e5de735d4ea4f5d3083
[DEBUG] kmpkg-cmake|1b3dac4b9b0bcbef227c954b495174863feebe3900b2a6bdef0cd1cf04ca1213
[DEBUG] kmpkg-cmake-wrapper.cmake|5d49ef2ee6448479c2aad0e5f732e2676eaba0411860f9bebabe6002d66f57d1
[DEBUG] kmpkg.json|bc94e2540efabe36130a806381a001c57194e7de67454ab7ff1e30aa15e6ce23
[DEBUG] kmpkg_copy_pdbs|d57e4f196c82dc562a9968c6155073094513c31e2de475694143d3aa47954b1c
[DEBUG] kmpkg_fixup_pkgconfig|588d833ff057d3ca99c14616c7ecfb5948b5e2a9e4fc02517dceb8b803473457
[DEBUG] kmpkg_from_git|8f27bff0d01c6d15a3e691758df52bfbb0b1b929da45c4ebba02ef76b54b1881
[DEBUG] kmpkg_from_github|b743742296a114ea1b18ae99672e02f142c4eb2bef7f57d36c038bedbfb0502f
[DEBUG] kmpkg_replace_string|d43c8699ce27e25d47367c970d1c546f6bc36b6df8fb0be0c3986eb5830bd4f1
[DEBUG] </abientries>
The
triplet_abientry contains three hashes: the hash of the file content of thex86-windowstriplet, thewindows.cmaketoolchain, and the compiler hash. These hashes would change if you decided to target a different platform.