C / C++ Guide
Artifact Keeper supports C/C++ package management through Conan v2 and Bazel, enabling you to host private C/C++ libraries and dependencies.
Conan (v2)
Artifact Keeper provides full support for Conan v2, the modern C/C++ package manager.
Configuration
Endpoint Format: /conan/{repo}
Repository Key: conan
Supported Clients: conan (v2.x)
Adding a Remote
Configure your Conan client to use Artifact Keeper as a remote repository:
# Add remote repositoryconan remote add artifact-keeper https://artifacts.example.com/conan/main
# List configured remotesconan remote list
# Set remote as defaultconan remote set-default artifact-keeperAuthentication
Authenticate with your Artifact Keeper credentials:
# Login to remoteconan remote login artifact-keeper <username>
# Or provide password directlyconan remote login artifact-keeper <username> -p <password>
# Verify authenticationconan remote list-usersAlternatively, configure authentication in your ~/.conan2/global.conf:
[credentials]artifact-keeper:user=<username>artifact-keeper:password=<password>Publishing Packages
Upload your Conan packages to Artifact Keeper:
# Create and export packageconan create . --user=mycompany --channel=stable
# Upload package to remoteconan upload mylibrary/1.0.0@mycompany/stable -r artifact-keeper --all
# Upload all packagesconan upload "*" -r artifact-keeper --all --confirmInstalling Packages
Install packages from Artifact Keeper:
# Install specific packageconan install mylibrary/1.0.0@mycompany/stable -r artifact-keeper
# Install from conanfile.txtconan install . -r artifact-keeper
# Install with specific profileconan install . -r artifact-keeper --profile=releaseProfiles and Settings
Create custom profiles for your build configurations:
# Create profileconan profile detect --force
# Custom profile example (~/.conan2/profiles/release)[settings]os=Linuxarch=x86_64compiler=gcccompiler.version=11compiler.libcxx=libstdc++11build_type=Release
[conf]tools.cmake.cmaketoolchain:generator=NinjaUse profiles when installing:
conan install . --profile=release -r artifact-keeperconanfile.py Example
from conan import ConanFilefrom conan.tools.cmake import CMake, cmake_layout
class MyLibraryConan(ConanFile): name = "mylibrary" version = "1.0.0"
# Metadata license = "MIT" author = "Your Company" description = "A C++ library" topics = ("cpp", "library")
# Configuration settings = "os", "compiler", "build_type", "arch" options = {"shared": [True, False], "fPIC": [True, False]} default_options = {"shared": False, "fPIC": True}
# Sources exports_sources = "src/*", "include/*", "CMakeLists.txt"
def requirements(self): # Dependencies from Artifact Keeper self.requires("boost/1.81.0@mycompany/stable") self.requires("fmt/9.1.0@mycompany/stable")
def layout(self): cmake_layout(self)
def build(self): cmake = CMake(self) cmake.configure() cmake.build()
def package(self): cmake = CMake(self) cmake.install()
def package_info(self): self.cpp_info.libs = ["mylibrary"]conanfile.txt Example
For simpler projects, use conanfile.txt:
[requires]boost/1.81.0@mycompany/stablefmt/9.1.0@mycompany/stablespdlog/1.11.0@mycompany/stable
[generators]CMakeDepsCMakeToolchain
[options]boost:shared=FalseThen install dependencies:
conan install . --output-folder=build --build=missing -r artifact-keeperBazel
Artifact Keeper supports Bazel modules through the Bazel Central Registry (BCR) protocol.
Configuration
Endpoint Format: /bazel/{repo}
Repository Key: bazel
Supported Clients: bazel, bazelisk
MODULE.bazel Configuration
Configure your Bazel workspace to use Artifact Keeper as a registry:
module( name = "my_project", version = "1.0.0",)
# Configure Artifact Keeper registrybazel_dep(name = "rules_cc", version = "0.0.9")
# Add custom registry# Configure in .bazelrc instead (see below)Registry Configuration
Add Artifact Keeper as a Bazel registry in your .bazelrc:
common --registry=https://artifacts.example.com/bazel/maincommon --registry=https://bcr.bazel.build # Fallback to public BCROr configure via environment variable:
export BAZEL_REGISTRY=https://artifacts.example.com/bazel/mainAuthentication
Configure authentication in your .netrc file:
machine artifacts.example.comlogin <username>password <token>Or use Bazel credential helpers:
common --credential_helper=artifacts.example.com=/path/to/credential-helperUsing Modules
Reference modules from your Artifact Keeper registry:
bazel_dep(name = "my_cpp_library", version = "1.2.3")bazel_dep(name = "common_utils", version = "2.0.0")
# Override module registry (if needed)single_version_override( module_name = "my_cpp_library", registry = "https://artifacts.example.com/bazel/main",)Publishing Modules
To publish a Bazel module to Artifact Keeper, create the module metadata:
{ "homepage": "https://github.com/myorg/my-library", "maintainers": [ { "email": "team@example.com", "name": "My Team" } ], "versions": ["1.0.0", "1.1.0"], "yanked_versions": {}}Create module source archive and upload:
# Create module archivetar czf my_cpp_library-1.0.0.tar.gz MODULE.bazel src/ BUILD.bazel
# Calculate integrity hashsha256sum my_cpp_library-1.0.0.tar.gz
# Upload via HTTP API (see Generic section for details)curl -X POST \ -H "Authorization: Bearer $TOKEN" \ -F "file=@my_cpp_library-1.0.0.tar.gz" \ https://artifacts.example.com/bazel/main/modules/my_cpp_library/1.0.0/source.jsonMODULE.bazel Example
module( name = "my_cpp_library", version = "1.0.0", compatibility_level = 1,)
# Dependenciesbazel_dep(name = "rules_cc", version = "0.0.9")bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True)bazel_dep(name = "abseil-cpp", version = "20230802.0")
# Toolchain registrationregister_toolchains("//toolchains:all")BUILD.bazel Example
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library( name = "my_library", srcs = glob(["src/**/*.cpp"]), hdrs = glob(["include/**/*.h"]), visibility = ["//visibility:public"], deps = [ "@abseil-cpp//absl/strings", "@abseil-cpp//absl/status", ],)Best Practices
Version Management
- Use semantic versioning for all packages
- Tag stable releases with
stablechannel (Conan) - Keep development versions in separate channels/repos
Dependencies
- Pin specific versions in production
- Use version ranges for development
- Document all external dependencies
CI/CD Integration
# Example GitHub Actions workflowname: Build and Publish
on: push: tags: - 'v*'
jobs: publish-conan: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Install Conan run: pip install conan
- name: Configure Remote run: | conan remote add artifact-keeper ${{ secrets.ARTIFACT_KEEPER_URL }}/conan/main conan remote login artifact-keeper ${{ secrets.ARTIFACT_KEEPER_USER }} -p ${{ secrets.ARTIFACT_KEEPER_TOKEN }}
- name: Create and Upload Package run: | conan create . --user=mycompany --channel=stable conan upload "*" -r artifact-keeper --all --confirmSecurity
- Use token authentication in CI/CD
- Rotate credentials regularly
- Restrict write access to production repositories
- Enable audit logging for package uploads
Troubleshooting
Conan Issues
Package not found:
# Verify remote configurationconan remote list
# Search for packageconan search mylibrary -r artifact-keeper
# Check authenticationconan remote list-usersUpload fails:
# Verify package exists locallyconan list "*"
# Check credentialsconan remote login artifact-keeper <username> -p <password>
# Verbose outputconan upload mylibrary/1.0.0 -r artifact-keeper --all -vvBazel Issues
Module not found:
# Verify registry configurationbazel config --show_flags | grep registry
# Check network connectivitycurl -I https://artifacts.example.com/bazel/main
# Verbose outputbazel build //... --verbose_failuresAuthentication fails:
# Verify .netrc configurationcat ~/.netrc
# Test authenticationcurl -n https://artifacts.example.com/bazel/mainNext Steps
- Learn about repository management
- Configure access control
- Set up CI/CD integration
- Explore other package formats