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
46 changes: 46 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This configuration should work with Clang-Format 18 and higher.
---
Language: Cpp
BasedOnStyle: LLVM

AlignArrayOfStructures: Left
AllowAllConstructorInitializersOnNextLine: false
AllowShortFunctionsOnASingleLine: Inline
AlwaysBreakBeforeMultilineStrings: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterFunction: true
AfterStruct: true
AfterUnion: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
ColumnLimit: 100
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
IncludeBlocks: Regroup
IncludeCategories:
# Relative headers
- Regex: '^"'
Priority: 1
# Dependency headers:
- Regex: '^<(uv\.h|curl/curl\.h)>$'
Priority: 3
# System headers:
- Regex: '\.h.*>$'
Priority: 4
# C++ headers:
- Regex: '^<'
Priority: 5
IndentPPDirectives: AfterHash
InsertNewlineAtEOF: true
KeepEmptyLinesAtTheStartOfBlocks: false
PackConstructorInitializers: Never
PointerAlignment: Left
SpaceAfterTemplateKeyword: false
Standard: c++17
31 changes: 28 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
name: Build

on: [push]
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
noop:
build:
runs-on: ubuntu-24.04

steps:
- run: echo "Actions enabled"
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev libuv1-dev cmake build-essential

- name: Configure
run: cmake -B build -D CMAKE_BUILD_TYPE=Release

- name: Build
run: cmake --build build

- name: Install
run: sudo cmake --install build

- name: Verify installation
run: |
test -f /usr/local/bin/ccache-storage-http
test -L /usr/local/bin/ccache-storage-https
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*~
/build/
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

## [0.1] - 2026-01-18

### Added

- Implemented first version.
63 changes: 63 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
cmake_minimum_required(VERSION 3.16)
project(ccache-storage-http VERSION 0.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(CURL QUIET CONFIG)
if(NOT CURL_FOUND)
find_package(PkgConfig REQUIRED)
pkg_check_modules(CURL REQUIRED IMPORTED_TARGET libcurl)
endif()

find_package(libuv QUIET CONFIG)
if(NOT libuv_FOUND)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBUV REQUIRED IMPORTED_TARGET libuv)
endif()

set(
SOURCES
src/config.cpp
src/ipc_server.cpp
src/logger.cpp
src/main.cpp
src/storage_client.cpp
)

add_executable(ccache-storage-http ${SOURCES})

if(TARGET CURL::libcurl)
target_link_libraries(ccache-storage-http PRIVATE CURL::libcurl)
else()
target_link_libraries(ccache-storage-http PRIVATE PkgConfig::CURL)
endif()

if(TARGET libuv::uv_a)
target_link_libraries(ccache-storage-http PRIVATE libuv::uv_a)
elseif(TARGET libuv::libuv)
target_link_libraries(ccache-storage-http PRIVATE libuv::libuv)
else()
target_link_libraries(ccache-storage-http PRIVATE PkgConfig::LIBUV)
endif()

if(WIN32)
target_compile_definitions(ccache-storage-http PRIVATE _WIN32_WINNT=0x0601 WIN32_LEAN_AND_MEAN NOGDI NOMINMAX)
if(MSVC)
target_compile_options(ccache-storage-http PRIVATE /W2)
else()
target_compile_options(ccache-storage-http PRIVATE -Wall -Wextra)
endif()
else()
target_compile_options(ccache-storage-http PRIVATE -Wall -Wextra)
endif()

install(TARGETS ccache-storage-http RUNTIME DESTINATION bin)
install(CODE "execute_process(COMMAND \${CMAKE_COMMAND} -E create_symlink ccache-storage-http \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin/ccache-storage-https)")

find_program(CLANG_FORMAT clang-format)
if(CLANG_FORMAT)
file(GLOB_RECURSE ALL_SOURCE_FILES src/*.cpp src/*.hpp)
add_custom_target(format COMMAND ${CLANG_FORMAT} -i ${ALL_SOURCE_FILES} COMMENT "Running clang-format on all source files" VERBATIM)
endif()
26 changes: 26 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright 2026 Joel Rosdahl

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
128 changes: 128 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# ccache-storage-http-cpp

A [ccache remote storage helper](https://ccache.dev/storage-helpers.html) for
HTTP/HTTPS storage, written in **C++**.

## Overview

This is a storage helper for [ccache] that enables caching compilation results
on HTTP/HTTPS servers. It implements the [ccache remote storage helper
protocol].

This project aims to:

1. Provide a high-performance, production-ready HTTP(S) ccache storage helper.
2. Serve as an example implementation of a ccache storage helper in **C++**.
Feel free to use it as a starting point for implementing helpers for other
storage service protocols.

See also the similar [ccache-remote-http-go] project for an example (and
production ready) **Go** implementation.

[ccache]: https://ccache.dev
[ccache remote storage helper protocol]: https://github.com/jrosdahl/ccache/blob/crsh/doc/remote_storage_helper_spec.md
[ccache-remote-http-go]: https://github.com/ccache/ccache-storage-http-go

## Features

- Supports HTTP and HTTPS
- High-performance concurrent request handling
- HTTP keep-alive for efficient connection reuse
- Cross-platform: Linux, macOS, Windows
- Multiple layout modes: `flat`, `subdirs`, `bazel`
- Bearer token authentication support
- Support for custom HTTP headers
- Optional debug logging

## Installation

The helper should be installed in a [location where ccache searches for helper
programs]. Install it as the name `ccache-storage-http` for HTTP support and/or
`ccache-storage-https` for HTTPS support.

[location where ccache searches for helper programs]: https://github.com/jrosdahl/ccache/blob/crsh/doc/manual.adoc#storage-helper-process

### Building from source

Make sure you have needed dependencies installed:

- [libcurl](https://curl.se/libcurl/)
- [libuv](https://libuv.org)
- [CMake](https://cmake.org) 3.16+
- C++17 compiler

(You can also install dependencies and build the project using
[Conan](https://docs.conan.io/2/).)

Clone the repository:

```bash
git clone https://github.com/ccache/ccache-storage-http-cpp
cd ccache-storage-http-cpp
```

Build and install:

```bash
cmake -B build -D CMAKE_BUILD_TYPE=Release
cmake --build build
cmake --install build
```

This will install both `ccache-storage-http` and `ccache-storage-https` to
`/usr/local/bin`. Pass `-D CMAKE_INSTALL_PREFIX=/example/dir` to `cmake` to
install elsewhere.

## Configuration

The helper is configured via ccache's [`remote_storage` configuration]. The
binary is automatically invoked by ccache when needed.

For example:

```bash
# Set the CCACHE_REMOTE_STORAGE environment variable:
export CCACHE_REMOTE_STORAGE="https://cache.example.com"

# Or set remote_storage in ccache's configuration file:
ccache -o remote_storage="https://cache.example.com"
```

[`remote_storage` configuration]: https://github.com/jrosdahl/ccache/blob/crsh/doc/manual.adoc#remote-storage-backends

See also the [HTTP storage wiki page] for tips on how to set up a storage server.

[HTTP storage wiki page]: https://github.com/ccache/ccache/wiki/HTTP-storage

### Configuration attributes

The helper supports the following custom attributes:

- `@bearer-token`: Bearer token for `Authorization` header
- `@header`: Custom HTTP headers (can be specified multiple times)
- `@layout`: Storage layout mode
- `subdirs` (default): First 2 hex chars as subdirectory
- `flat`: All files in root directory
- `bazel`: Bazel Remote Execution API compatible layout

Example:

```bash
export CCACHE_REMOTE_STORAGE="https://cache.example.com @header=Content-Type=application/octet-stream"
```

## Optional debug logging

You can set the `CRSH_LOGFILE` environment variable to enable debug logging to a
file:

```bash
export CRSH_LOGFILE=/path/to/debug.log
```

Note: The helper process is spawned by ccache, so the environment variable must
be set before ccache is invoked.

## Contributing

Contributions are welcome! Please submit pull requests or open issues on GitHub.
12 changes: 12 additions & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[requires]
libcurl/8.11.1
libuv/1.49.2

[generators]
CMakeDeps
CMakeToolchain

[options]

[layout]
cmake_layout
Loading