-
Notifications
You must be signed in to change notification settings - Fork 2
feat(farmhash): add LLAR formula #137
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,33 @@ | ||
| cmake_minimum_required(VERSION 3.15) | ||
| project(farmhash LANGUAGES CXX) | ||
|
|
||
| include(GNUInstallDirs) | ||
|
|
||
| if(NOT FARMHASH_NO_BUILTIN_EXPECT) | ||
| # Transcribed from farmhash/src/Makefile.am | ||
| include(CheckCXXSourceCompiles) | ||
| check_cxx_source_compiles( | ||
| "int main(int argc, char* argv[]) { return (int)__builtin_expect(0, 0); }" | ||
| FARMHASH_HAS_BUILTIN_EXPECT | ||
| ) | ||
| endif() | ||
|
|
||
| add_library(farmhash "${FARMHASH_SRC_DIR}/src/farmhash.cc" ) | ||
| target_include_directories(farmhash PRIVATE "${FARMHASH_SRC_DIR}/src") | ||
|
|
||
| if(NOT FARMHASH_HAS_BUILTIN_EXPECT) | ||
| target_compile_definitions(farmhash PUBLIC FARMHASH_NO_BUILTIN_EXPECT) | ||
| endif() | ||
|
|
||
| set_target_properties(farmhash | ||
| PROPERTIES | ||
| PUBLIC_HEADER "${FARMHASH_SRC_DIR}/src/farmhash.h" | ||
| WINDOWS_EXPORT_ALL_SYMBOLS ON | ||
| ) | ||
|
|
||
| install(TARGETS farmhash | ||
| RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
| LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "slices" | ||
| "strings" | ||
| ) | ||
|
|
||
| const consumerSource = `#include <farmhash.h> | ||
|
|
||
| #include <iostream> | ||
| #include <string> | ||
|
|
||
| int main() { | ||
| std::string aString = "Conan"; | ||
| uint32_t hashResult; | ||
|
|
||
| hashResult = util::Hash32(aString); | ||
|
|
||
| std::cout << "Input string: " << aString << std::endl; | ||
| std::cout << "Generated hash: " << hashResult << std::endl; | ||
|
|
||
| return 0; | ||
| } | ||
| ` | ||
|
|
||
| id "google/farmhash" | ||
|
|
||
| fromVer "0d859a811870d10f53a594927d0d0b97573ad06d" | ||
|
|
||
| defaults { | ||
| "shared": "OFF", | ||
| "fPIC": "ON", | ||
| "no_builtin_expect": "OFF", | ||
|
Contributor
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. Document the options, especially |
||
| } | ||
|
|
||
| filter => { | ||
| for name, values in target.options { | ||
| if name != "shared" && name != "fPIC" && name != "no_builtin_expect" { | ||
| return false | ||
| } | ||
| for value in values { | ||
| if value != "ON" && value != "OFF" { | ||
| return false | ||
| } | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| onBuild ctx => { | ||
| installDir := ctx.outputDir | ||
|
|
||
| cmakeLists := ctx.Proj.readFile("0d859a811870d10f53a594927d0d0b97573ad06d/CMakeLists.txt")! | ||
|
Contributor
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. Version hash literal is duplicated. The commit hash |
||
| os.writeFile(filepath.join(ctx.SourceDir, "CMakeLists.txt"), cmakeLists, 0o644)! | ||
|
|
||
| shared := slices.contains(target.options["shared"], "ON") | ||
| fPIC := slices.contains(target.options["fPIC"], "ON") | ||
|
Contributor
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.
|
||
| noBuiltinExpect := slices.contains(target.options["no_builtin_expect"], "ON") | ||
|
|
||
| c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) | ||
| c.define "FARMHASH_SRC_DIR", ctx.SourceDir | ||
| c.defineBool "BUILD_SHARED_LIBS", shared | ||
| c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC | ||
| c.defineBool "FARMHASH_NO_BUILTIN_EXPECT", noBuiltinExpect | ||
| c.configure | ||
| c.build | ||
| c.install | ||
|
|
||
| licenseDir := filepath.join(installDir, "licenses") | ||
| os.mkdirAll(licenseDir, 0o755)! | ||
| os.writeFile(filepath.join(licenseDir, "COPYING"), os.readFile(filepath.join(ctx.SourceDir, "COPYING"))!, 0o644)! | ||
|
|
||
| flags := []string{ | ||
| "-I" + filepath.join(installDir, "include"), | ||
| "-L" + filepath.join(installDir, "lib"), | ||
| "-lfarmhash", | ||
| } | ||
| ctx.setMetadata strings.join(flags, " ") | ||
| } | ||
|
|
||
| onTest ctx => { | ||
| installDir := ctx.outputDir | ||
| testDir := filepath.join(ctx.SourceDir, "_llar_consumer") | ||
| os.mkdirAll(testDir, 0o755)! | ||
|
|
||
| consumer := filepath.join(testDir, "consumer.cpp") | ||
| os.writeFile(consumer, []byte(consumerSource), 0o644)! | ||
|
|
||
| binary := filepath.join(testDir, "consumer") | ||
| flags := []string{ | ||
| "-I" + filepath.join(installDir, "include"), | ||
| consumer, | ||
| "-L" + filepath.join(installDir, "lib"), | ||
| "-lfarmhash", | ||
| "-o", binary, | ||
| } | ||
| exec "c++", flags... | ||
| lastErr! | ||
|
|
||
| if slices.contains(target.options["shared"], "ON") { | ||
| os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
|
Contributor
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.
|
||
| os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| } | ||
| exec binary | ||
| lastErr! | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "google/farmhash", | ||
| "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.
Non-obvious
no_builtin_expectsemantics are correct but undocumented. Tracing the logic: withno_builtin_expect=ONthe probe is skipped (if(NOT ON)is false), leavingFARMHASH_HAS_BUILTIN_EXPECTempty, so line 18'sif(NOT FARMHASH_HAS_BUILTIN_EXPECT)is true and the macro is defined — force-disable works. WithOFF(default) the probe runs and auto-detects. SoOFFmeans "auto-detect," not "builtin is used." ThisON=force / OFF=autodetectcontract, plus the fact that the macro is exportedPUBLIC(propagates to consumers), is worth a brief comment either here or in the.gox.