Skip to content

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:

Terminal window
# Add remote repository
conan remote add artifact-keeper https://artifacts.example.com/conan/main
# List configured remotes
conan remote list
# Set remote as default
conan remote set-default artifact-keeper

Authentication

Authenticate with your Artifact Keeper credentials:

Terminal window
# Login to remote
conan remote login artifact-keeper <username>
# Or provide password directly
conan remote login artifact-keeper <username> -p <password>
# Verify authentication
conan remote list-users

Alternatively, 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:

Terminal window
# Create and export package
conan create . --user=mycompany --channel=stable
# Upload package to remote
conan upload mylibrary/1.0.0@mycompany/stable -r artifact-keeper --all
# Upload all packages
conan upload "*" -r artifact-keeper --all --confirm

Installing Packages

Install packages from Artifact Keeper:

Terminal window
# Install specific package
conan install mylibrary/1.0.0@mycompany/stable -r artifact-keeper
# Install from conanfile.txt
conan install . -r artifact-keeper
# Install with specific profile
conan install . -r artifact-keeper --profile=release

Profiles and Settings

Create custom profiles for your build configurations:

Terminal window
# Create profile
conan profile detect --force
# Custom profile example (~/.conan2/profiles/release)
[settings]
os=Linux
arch=x86_64
compiler=gcc
compiler.version=11
compiler.libcxx=libstdc++11
build_type=Release
[conf]
tools.cmake.cmaketoolchain:generator=Ninja

Use profiles when installing:

Terminal window
conan install . --profile=release -r artifact-keeper

conanfile.py Example

from conan import ConanFile
from 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/stable
fmt/9.1.0@mycompany/stable
spdlog/1.11.0@mycompany/stable
[generators]
CMakeDeps
CMakeToolchain
[options]
boost:shared=False

Then install dependencies:

Terminal window
conan install . --output-folder=build --build=missing -r artifact-keeper

Bazel

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.bazel
module(
name = "my_project",
version = "1.0.0",
)
# Configure Artifact Keeper registry
bazel_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:

.bazelrc
common --registry=https://artifacts.example.com/bazel/main
common --registry=https://bcr.bazel.build # Fallback to public BCR

Or configure via environment variable:

Terminal window
export BAZEL_REGISTRY=https://artifacts.example.com/bazel/main

Authentication

Configure authentication in your .netrc file:

~/.netrc
machine artifacts.example.com
login <username>
password <token>

Or use Bazel credential helpers:

.bazelrc
common --credential_helper=artifacts.example.com=/path/to/credential-helper

Using Modules

Reference modules from your Artifact Keeper registry:

MODULE.bazel
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:

metadata.json
{
"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:

Terminal window
# Create module archive
tar czf my_cpp_library-1.0.0.tar.gz MODULE.bazel src/ BUILD.bazel
# Calculate integrity hash
sha256sum 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.json

MODULE.bazel Example

module(
name = "my_cpp_library",
version = "1.0.0",
compatibility_level = 1,
)
# Dependencies
bazel_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 registration
register_toolchains("//toolchains:all")

BUILD.bazel Example

BUILD.bazel
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 stable channel (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 workflow
name: 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 --confirm

Security

  • 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:

Terminal window
# Verify remote configuration
conan remote list
# Search for package
conan search mylibrary -r artifact-keeper
# Check authentication
conan remote list-users

Upload fails:

Terminal window
# Verify package exists locally
conan list "*"
# Check credentials
conan remote login artifact-keeper <username> -p <password>
# Verbose output
conan upload mylibrary/1.0.0 -r artifact-keeper --all -vv

Bazel Issues

Module not found:

Terminal window
# Verify registry configuration
bazel config --show_flags | grep registry
# Check network connectivity
curl -I https://artifacts.example.com/bazel/main
# Verbose output
bazel build //... --verbose_failures

Authentication fails:

Terminal window
# Verify .netrc configuration
cat ~/.netrc
# Test authentication
curl -n https://artifacts.example.com/bazel/main

Next Steps