-
Notifications
You must be signed in to change notification settings - Fork 2
feat(poshlib): add LLAR formula #141
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,140 @@ | ||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "runtime" | ||
| "slices" | ||
| "strings" | ||
| ) | ||
|
|
||
| const cmakeLists = `cmake_minimum_required(VERSION 3.12) | ||
| project(poshlib C) | ||
|
|
||
| if(WIN32 AND BUILD_SHARED_LIBS) | ||
| set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
| endif() | ||
|
|
||
| file(GLOB SRCS_FILES $${POSH_SRC_DIR}/*.c) | ||
| file(GLOB HDRS_FILES $${POSH_SRC_DIR}/*.h) | ||
|
|
||
| add_library(posh $${SRCS_FILES}) | ||
| target_include_directories(posh PUBLIC $${POSH_SRC_DIR}) | ||
|
|
||
| include(GNUInstallDirs) | ||
| install(TARGETS posh | ||
| LIBRARY DESTINATION $${CMAKE_INSTALL_LIBDIR} | ||
| ARCHIVE DESTINATION $${CMAKE_INSTALL_LIBDIR} | ||
| RUNTIME DESTINATION $${CMAKE_INSTALL_BINDIR}) | ||
| install(FILES $${HDRS_FILES} DESTINATION $${CMAKE_INSTALL_INCLUDEDIR}) | ||
| ` | ||
|
|
||
| const consumerSource = `#include <stdio.h> | ||
|
|
||
| #include "posh.h" | ||
|
|
||
| int main(void) | ||
| { | ||
| printf("%s", POSH_GetArchString()); | ||
| return 0; | ||
| } | ||
| ` | ||
|
|
||
| id "PhilipLudington/poshlib" | ||
|
|
||
| fromVer "v1.3.002" | ||
|
|
||
| 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 | ||
| } | ||
|
Comment on lines
+45
to
+62
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] Option/default semantics are undocumented vs. sibling recipes The |
||
|
|
||
| onBuild ctx => { | ||
| installDir := ctx.outputDir | ||
|
|
||
| // The CCI recipe adds arm64 compiler spellings to the upstream ARM check. | ||
| headerPath := filepath.join(ctx.SourceDir, "posh.h") | ||
| header := string(os.readFile(headerPath)!) | ||
| header = strings.replace(header, "defined _ARM", "defined _ARM || defined __arm64 || defined __arm64__ || defined __aarch64__", 1) | ||
| os.writeFile(headerPath, []byte(header), 0644)! | ||
|
Comment on lines
+68
to
+71
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. [P2] Header patch is not idempotent on a reused source tree The replacement anchor A guard makes it safe and skips the write on re-runs, e.g. |
||
|
|
||
| cmakeDir := filepath.join(ctx.SourceDir, "_llar_cmake") | ||
| os.mkdirAll(cmakeDir, 0755)! | ||
| os.writeFile(filepath.join(cmakeDir, "CMakeLists.txt"), []byte(cmakeLists), 0644)! | ||
|
|
||
| shared := slices.contains(target.options["shared"], "ON") | ||
| fPIC := slices.contains(target.options["fPIC"], "ON") | ||
| c := cmake.new(cmakeDir, filepath.join(ctx.SourceDir, "_build"), installDir) | ||
| c.define "POSH_SRC_DIR", ctx.SourceDir | ||
| c.define "CMAKE_INSTALL_LIBDIR", "lib" | ||
| c.defineBool "BUILD_SHARED_LIBS", shared | ||
| if !shared { | ||
| c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC | ||
| } | ||
| c.configure | ||
| c.build | ||
| c.install | ||
|
|
||
| licenseDir := filepath.join(installDir, "licenses") | ||
| os.mkdirAll(licenseDir, 0755)! | ||
| os.writeFile(filepath.join(licenseDir, "LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE"))!, 0644)! | ||
|
|
||
| osName := runtime.GOOS | ||
| osValues := target.require["os"] | ||
| if osValues.len > 0 { | ||
| osName = osValues[0] | ||
| } | ||
| metadata := "-I" + filepath.join(installDir, "include") + " -L" + filepath.join(installDir, "lib") + " -lposh" | ||
| if shared && osName == "windows" { | ||
| metadata = "-DPOSH_DLL " + metadata | ||
| } | ||
|
Comment on lines
+99
to
+102
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] Metadata is hand-built rather than derived from an installed interface
|
||
| ctx.setMetadata metadata | ||
| } | ||
|
|
||
| onTest ctx => { | ||
| installDir := ctx.outputDir | ||
| testDir := filepath.join(ctx.SourceDir, "_llar_consumer") | ||
| os.mkdirAll(testDir, 0755)! | ||
|
|
||
| sourcePath := filepath.join(testDir, "consumer.c") | ||
| os.writeFile(sourcePath, []byte(consumerSource), 0644)! | ||
|
|
||
| shared := slices.contains(target.options["shared"], "ON") | ||
| osName := runtime.GOOS | ||
| osValues := target.require["os"] | ||
| if osValues.len > 0 { | ||
| osName = osValues[0] | ||
| } | ||
| binary := filepath.join(testDir, "consumer") | ||
| args := []string{ | ||
| "-I" + filepath.join(installDir, "include"), | ||
| sourcePath, | ||
| "-L" + filepath.join(installDir, "lib"), | ||
| "-lposh", | ||
| "-o", binary, | ||
| } | ||
| if shared && osName == "windows" { | ||
| args = append([]string{"-DPOSH_DLL"}, args...) | ||
| } | ||
| exec "cc", args... | ||
| lastErr! | ||
|
|
||
| if shared { | ||
| os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| } | ||
|
Comment on lines
+134
to
+137
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. [P2] Shared-build test: overwrites loader env and misses Windows DLL resolution Two issues in the shared-library test path:
|
||
| exec binary | ||
| lastErr! | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "PhilipLudington/poshlib", | ||
| "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.
[P1] filter rejects targets that carry any option beyond shared/fPIC
The
filteriterates every key intarget.optionsand returnsfalsefor any name that isn'tsharedorfPIC. If the loader ever surfaces another standard key (e.g.os, arch, build type) intarget.options, an otherwise valid selection is silently rejected as "no matching target" rather than failing with a clear cause.The write-formula semantics guidance is explicit here: "Reject a selection only when the selected upstream revision proves it is unsupported" and "Defaults choose option values; they do not by themselves define every legal value." The sibling
recp/cglmrecipe follows the safer pattern — it validates only the values of the option(s) it cares about and never enumerates/rejects unknown keys.Consider validating only the values of
shared/fPICinstead of rejecting unrecognized option names.