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
17 changes: 17 additions & 0 deletions evgenykislov/ctrl-c/v1.0.0/CMakeLists.txt
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}
)
96 changes: 96 additions & 0 deletions evgenykislov/ctrl-c/v1.0.0/ctrl_c_llar.gox
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"

Copy link
Copy Markdown
Contributor

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_LIBDIR is forced to lib, and the hardcoded -L.../lib flags at lines 64 and 83 depend on this. Since CMakeLists.txt includes GNUInstallDirs (which selects lib64 on 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.

c.defineBool "BUILD_SHARED_LIBS", shared
c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 shared=ON, fPIC=OFF. A shared library requires position-independent code, but this passes CMAKE_POSITION_INDEPENDENT_CODE=OFF while BUILD_SHARED_LIBS=ON, which will typically fail to link on most toolchains.

Suggest either forcing PIC on for the shared case, e.g. fPIC := shared || slices.contains(target.options["fPIC"], "ON"), or rejecting the invalid combination in filter.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 LD_LIBRARY_PATH/DYLD_LIBRARY_PATH to the install lib dir, discarding any existing value. Prepending (installDir/lib + ":" + os.getenv(...)) is safer if toolchain/runtime libs live elsewhere. Low priority — usually harmless in a sandboxed runner.

}
exec binary
lastErr!
}
4 changes: 4 additions & 0 deletions evgenykislov/ctrl-c/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "evgenykislov/ctrl-c",
"deps": {}
}
Loading