-
Notifications
You must be signed in to change notification settings - Fork 2
feat(google/crc32c): add LLAR formula for crc32c 1.1.1+ #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| } | ||
| ` | ||
| 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" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: |
||
| // 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 | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "google/crc32c", | ||
| "deps": {} | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onTestis effectively a tautology and does not validate CRC correctness.a = crc32c::Crc32c(buffer, 4)runs over 4 zero bytes, andb = crc32c::Crc32c(s)runs over astd::stringof size 4 (default-filled with'\0'). Thestd::stringoverload just forwards the same bytes to the same routine, soa == bis guaranteed true by construction — the check passes even ifCrc32cwere 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 checkinga == b) turns this into a real smoke test that would catch a miscompiled/misconfigured library. A second vector such as"123456789"→0xE3069283would strengthen it further.