-
Notifications
You must be signed in to change notification settings - Fork 2
feat(ctrl-c): add LLAR formula #142
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,17 @@ | ||
| cmake_minimum_required(VERSION 3.15) | ||
| project(ctrl-c LANGUAGES CXX) | ||
|
|
||
| add_library(ctrl-c ${CTRL_C_SRC_DIR}/src/ctrl-c.cpp) | ||
| set_target_properties(ctrl-c PROPERTIES | ||
| PUBLIC_HEADER ${CTRL_C_SRC_DIR}/src/ctrl-c.h | ||
| ) | ||
| target_compile_features(ctrl-c PUBLIC cxx_std_11) | ||
|
|
||
| include(GNUInstallDirs) | ||
| install( | ||
| TARGETS ctrl-c | ||
| 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,96 @@ | ||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "slices" | ||
| "strings" | ||
| ) | ||
|
|
||
| const consumerSource = `#include "ctrl-c.h" | ||
|
|
||
| int main(void) { | ||
| auto id = CtrlCLibrary::SetCtrlCHandler([](CtrlCLibrary::CtrlSignal signal){ return true;}); | ||
| CtrlCLibrary::ResetCtrlCHandler(id); | ||
|
|
||
| return 0; | ||
| } | ||
| ` | ||
|
|
||
| id "evgenykislov/ctrl-c" | ||
|
|
||
| fromVer "v1.0.0" | ||
|
|
||
| defaults { | ||
| "shared": "OFF", | ||
| "fPIC": "ON", | ||
| } | ||
|
|
||
| filter => { | ||
| for name, values in target.options { | ||
| if name != "shared" && name != "fPIC" { | ||
| return false | ||
| } | ||
| for value in values { | ||
| if value != "ON" && value != "OFF" { | ||
| return false | ||
| } | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| onBuild ctx => { | ||
| installDir := ctx.outputDir | ||
|
|
||
| cmakeLists := ctx.Proj.readFile("v1.0.0/CMakeLists.txt")! | ||
| os.writeFile(filepath.join(ctx.SourceDir, "CMakeLists.txt"), cmakeLists, 0o644)! | ||
|
|
||
| shared := slices.contains(target.options["shared"], "ON") | ||
| fPIC := slices.contains(target.options["fPIC"], "ON") | ||
| c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) | ||
| c.define "CTRL_C_SRC_DIR", ctx.SourceDir | ||
| c.define "CMAKE_INSTALL_LIBDIR", "lib" | ||
| c.defineBool "BUILD_SHARED_LIBS", shared | ||
| c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC | ||
|
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. [P1] shared=ON with fPIC=OFF is allowed but produces an invalid build A consumer can request Suggest either forcing PIC on for the shared case, e.g. |
||
| c.configure | ||
| c.build | ||
| c.install | ||
|
|
||
| licenseDir := filepath.join(installDir, "licenses") | ||
| os.mkdirAll(licenseDir, 0o755)! | ||
| os.writeFile(filepath.join(licenseDir, "LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE"))!, 0o644)! | ||
|
|
||
| flags := []string{ | ||
| "-I" + filepath.join(installDir, "include"), | ||
| "-L" + filepath.join(installDir, "lib"), | ||
| "-lctrl-c", | ||
| } | ||
| ctx.setMetadata strings.join(flags, " ") | ||
| } | ||
|
|
||
| onTest ctx => { | ||
| installDir := ctx.outputDir | ||
| testDir := filepath.join(ctx.SourceDir, "_llar_consumer") | ||
| os.mkdirAll(testDir, 0o755)! | ||
|
|
||
| sourcePath := filepath.join(testDir, "consumer.cpp") | ||
| os.writeFile(sourcePath, []byte(consumerSource), 0o644)! | ||
|
|
||
| binary := filepath.join(testDir, "consumer") | ||
| args := []string{ | ||
| "-std=c++11", | ||
| "-I" + filepath.join(installDir, "include"), | ||
| sourcePath, | ||
| "-L" + filepath.join(installDir, "lib"), | ||
| "-lctrl-c", | ||
| "-o", binary, | ||
| } | ||
| exec "c++", args... | ||
| lastErr! | ||
|
|
||
| if slices.contains(target.options["shared"], "ON") { | ||
| os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
|
Comment on lines
+91
to
+92
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. [P3] LD_LIBRARY_PATH/DYLD_LIBRARY_PATH overwrite instead of prepend For the shared build the test sets |
||
| } | ||
| exec binary | ||
| lastErr! | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "evgenykislov/ctrl-c", | ||
| "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.
[P2] Undocumented CMAKE_INSTALL_LIBDIR override
CMAKE_INSTALL_LIBDIRis forced tolib, and the hardcoded-L.../libflags at lines 64 and 83 depend on this. SinceCMakeLists.txtincludesGNUInstallDirs(which selectslib64on some distros), a future edit removing this override would silently break the metadata and test flags on lib64 systems. json-c documents exactly this choice; a one-line comment here would prevent that regression.