Skip to content
Open
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
84 changes: 84 additions & 0 deletions google/crc32c/1.1.1/Crc32c_llar.gox
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import "os"

id "google/crc32c"

fromVer "1.1.1"

onBuild ctx => {
installDir := ctx.outputDir

c := cmake.new(ctx.SourceDir, ctx.SourceDir+"/_build", installDir)
c.buildType "Release"
// crc32c declares cmake_minimum_required(VERSION 3.1); allow CMake 4.
c.define "CMAKE_POLICY_VERSION_MINIMUM", "3.5"
// Build only the library and its public header; skip the tooling that
// pulls in vendored glog/googletest/benchmark subprojects.
c.defineBool "CRC32C_BUILD_TESTS", false
c.defineBool "CRC32C_BUILD_BENCHMARKS", false
c.defineBool "CRC32C_USE_GLOG", false
c.defineBool "CRC32C_INSTALL", true

c.configure
c.build
c.install

// crc32c installs a single library named crc32c and no pkg-config file.
ctx.setMetadata "-lcrc32c"
}

onTest ctx => {
installDir := ctx.outputDir

// Keep the consumer's build tree separate from onBuild's _build so the
// test also runs on a cache hit, where onBuild is skipped and _build
// never exists. Everything lives under a fresh scratch directory.
testDir := ctx.SourceDir + "/_consumer"
testBuild := testDir + "/_build"
os.mkdirAll(testDir, 0o755)!

// Minimal consumer mirroring the Conan test_package: include the public
// header and exercise both the raw-buffer and std::string overloads.
consumer := `#include <cstdint>
#include <string>
#include "crc32c/crc32c.h"

int main() {
const uint8_t buffer[4] = {0, 0, 0, 0};
std::uint32_t a = crc32c::Crc32c(buffer, sizeof(buffer));

std::string s;
s.resize(4);
std::uint32_t b = crc32c::Crc32c(s);

return (a == b) ? 0 : 1;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onTest is effectively a tautology and does not validate CRC correctness. a = crc32c::Crc32c(buffer, 4) runs over 4 zero bytes, and b = crc32c::Crc32c(s) runs over a std::string of size 4 (default-filled with '\0'). The std::string overload just forwards the same bytes to the same routine, so a == b is guaranteed true by construction — the check passes even if Crc32c were broken (e.g. returned a constant), since it only proves the two overloads agree, not that the CRC is computed correctly.

Assert against a known-answer constant instead. CRC32C over 4 zero bytes is 0x48674BC7; e.g. return (a == 0x48674BC7u) ? 0 : 1; (optionally still checking a == b) turns this into a real smoke test that would catch a miscompiled/misconfigured library. A second vector such as "123456789"0xE3069283 would strengthen it further.

}
`
os.writeFile(testDir+"/consumer.cpp", []byte(consumer), 0o644)!

cmakeLists := `cmake_minimum_required(VERSION 3.5)
project(crc32c_consumer CXX)
set(CMAKE_CXX_STANDARD 11)
# Consume via the exported CMake package (installed under lib/cmake/Crc32c);
# cmake.use puts the install root on CMAKE_PREFIX_PATH. The Crc32c::crc32c
# target carries its own include directories and library.
find_package(Crc32c CONFIG REQUIRED)
add_executable(crc32c_consumer consumer.cpp)
target_link_libraries(crc32c_consumer PRIVATE Crc32c::crc32c)
`
os.writeFile(testDir+"/CMakeLists.txt", []byte(cmakeLists), 0o644)!

tc := cmake.new(testDir, testBuild, "")
tc.buildType "Release"
tc.define "CMAKE_POLICY_VERSION_MINIMUM", "3.5"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: CMAKE_POLICY_VERSION_MINIMUM=3.5 is redundant here. The generated consumer CMakeLists.txt already declares cmake_minimum_required(VERSION 3.5), and CMake config packages (loaded via find_package(Crc32c CONFIG)) don't call cmake_minimum_required, so this shim is dead in the test path. It is justified in onBuild (line 13) because upstream's own top-level CMakeLists.txt requests VERSION 3.1. Consider dropping it from onTest, or add a note explaining which downstream file it guards.

// Put the install root on CMAKE_PREFIX_PATH so find_package locates it.
tc.use installDir

tc.configure
tc.build

// Run the consumer; a non-zero exit surfaces through lastErr.
exec testBuild + "/crc32c_consumer"
if lastErr != nil {
panic lastErr
}
}
4 changes: 4 additions & 0 deletions google/crc32c/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "google/crc32c",
"deps": {}
}