-
Notifications
You must be signed in to change notification settings - Fork 2
feat(libatomic_ops): add LLAR formula #139
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,156 @@ | ||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| ) | ||
|
|
||
| const consumerSource = `#include "atomic_ops_stack.h" | ||
|
|
||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| AO_t globalElement; | ||
|
|
||
| AO_stack_t globalStack = AO_STACK_INITIALIZER; | ||
|
|
||
| typedef struct { | ||
| AO_t head; | ||
| unsigned val; | ||
| } my_stack_t; | ||
|
|
||
| int main(void) | ||
| { | ||
| AO_store_full(&globalElement, 1337); | ||
| { | ||
| AO_t val = AO_load_full(&globalElement); | ||
| if (val != 1337) { | ||
| fprintf(stderr, "Unexpected element after store/load: %u\n", (unsigned) val); | ||
| return EXIT_FAILURE; | ||
| } | ||
| } | ||
|
|
||
| { | ||
| my_stack_t *newElem = (my_stack_t *) malloc(sizeof(my_stack_t)); | ||
| newElem->val = 4242; | ||
| AO_stack_push_release(&globalStack, &newElem->head); | ||
| } | ||
| { | ||
| my_stack_t *newElem = (my_stack_t *) malloc(sizeof(my_stack_t)); | ||
| newElem->val = 8484; | ||
| AO_stack_push_release(&globalStack, &newElem->head); | ||
| } | ||
|
|
||
| { | ||
| my_stack_t *fetchElement = (my_stack_t *) AO_stack_pop_acquire(&globalStack); | ||
| if (fetchElement->val != 8484) { | ||
| fprintf(stderr, "Unexpected element from stack: %u\n", (unsigned) fetchElement->val); | ||
| return EXIT_FAILURE; | ||
| } | ||
| free(fetchElement); | ||
| } | ||
| { | ||
| my_stack_t *fetchElement = (my_stack_t *) AO_stack_pop_acquire(&globalStack); | ||
| if (fetchElement->val != 4242) { | ||
| fprintf(stderr, "Unexpected element from stack: %u\n", (unsigned) fetchElement->val); | ||
| return EXIT_FAILURE; | ||
| } | ||
| free(fetchElement); | ||
| } | ||
| return EXIT_SUCCESS; | ||
| } | ||
| ` | ||
|
|
||
| id "bdwgc/libatomic_ops" | ||
|
|
||
| fromVer "v7.8.0" | ||
|
|
||
| defaults { | ||
| "shared": "OFF", | ||
| "fPIC": "ON", | ||
| "assertions": "OFF", | ||
| "atomic_intrinsics": "ON", | ||
| } | ||
|
|
||
| filter => { | ||
| for name, values in target.options { | ||
| if name != "shared" && name != "fPIC" && name != "assertions" && name != "atomic_intrinsics" { | ||
| return false | ||
| } | ||
| for value in values { | ||
| if value != "ON" && value != "OFF" { | ||
| return false | ||
| } | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| onBuild ctx => { | ||
| installDir := ctx.outputDir | ||
| shared := target.options["shared"][0] == "ON" | ||
| fPIC := target.options["fPIC"][0] == "ON" | ||
| assertions := target.options["assertions"][0] == "ON" | ||
| atomicIntrinsics := target.options["atomic_intrinsics"][0] == "ON" | ||
|
|
||
| c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) | ||
| c.define "CMAKE_INSTALL_LIBDIR", "lib" | ||
| c.define "CMAKE_POLICY_VERSION_MINIMUM", "3.5" | ||
| c.defineBool "BUILD_SHARED_LIBS", shared | ||
| c.defineBool "AO_BUILD_SHARED_LIBS", shared | ||
| c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC | ||
| c.defineBool "enable_assertions", assertions | ||
| c.defineBool "enable_atomic_intrinsics", atomicIntrinsics | ||
| c.defineBool "BUILD_TESTING", false | ||
| c.defineBool "enable_gpl", true | ||
| c.defineBool "install_headers", true | ||
| c.configure | ||
| c.build | ||
| c.install | ||
|
|
||
| licenseDir := filepath.join(installDir, "licenses") | ||
| os.mkdirAll(licenseDir, 0o755)! | ||
| for name in []string{"LICENSE", "COPYING"} { | ||
| license := os.readFile(filepath.join(ctx.SourceDir, name))! | ||
| os.writeFile(filepath.join(licenseDir, name), license, 0o644)! | ||
| } | ||
|
|
||
| // CMake writes the upstream pkg-config file with the build prefix. Keep | ||
| // its verified flags while making the installed package relocatable. | ||
| pcPath := filepath.join(installDir, "lib", "pkgconfig", "atomic_ops.pc") | ||
| pc := string(os.readFile(pcPath)!) | ||
| pc = strings.replace(pc, "prefix="+installDir, "prefix=$${pcfiledir}/../..", 1) | ||
|
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. Please verify the |
||
| os.writeFile(pcPath, []byte(pc), 0o644)! | ||
|
|
||
| pkgconfig.use installDir | ||
| ctx.setMetadata pkgconfig.lookup("atomic_ops")! | ||
| } | ||
|
|
||
| onTest ctx => { | ||
| installDir := ctx.outputDir | ||
| testDir := filepath.join(ctx.SourceDir, "_llar_consumer") | ||
| testBuild := filepath.join(testDir, "_build") | ||
| os.mkdirAll(testDir, 0o755)! | ||
| os.writeFile(filepath.join(testDir, "consumer.c"), []byte(consumerSource), 0o644)! | ||
|
|
||
| cmakeLists := `cmake_minimum_required(VERSION 3.15) | ||
| project(libatomic_ops_consumer C) | ||
|
|
||
| find_package(Atomic_ops CONFIG REQUIRED) | ||
|
|
||
| add_executable(consumer consumer.c) | ||
| target_link_libraries(consumer PRIVATE Atomic_ops::atomic_ops Atomic_ops::atomic_ops_gpl) | ||
| ` | ||
| os.writeFile(filepath.join(testDir, "CMakeLists.txt"), []byte(cmakeLists), 0o644)! | ||
|
|
||
| c := cmake.new(testDir, testBuild, "") | ||
| c.use installDir | ||
| c.configure | ||
| c.build | ||
|
|
||
| if target.options["shared"][0] == "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. These overwrite |
||
| os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| } | ||
| exec filepath.join(testBuild, "consumer") | ||
| lastErr! | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "bdwgc/libatomic_ops", | ||
| "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.
onBuild/onTestindextarget.options["..."][0]unconditionally (lines 90-93, 150), butfilter(74-86) only rejects unknown option names and non-ON/OFFvalues — it doesn't require each recognized option to carry a value. If a target supplies a recognized option with an empty value list,filterstill returnstrueand this[0]indexes into an empty slice.defaultscovers the common case, butfilteris what guards non-default targets. Consider validating a single non-empty value per option infilter, or use membership like cglm'sslices.contains(target.options["shared"], "ON")instead of positional[0].