-
Notifications
You must be signed in to change notification settings - Fork 2
feat(whereami): add LLAR formula #150
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,14 @@ | ||
| cmake_minimum_required(VERSION 3.12) | ||
| project(whereami C) | ||
|
|
||
| if (WIN32 AND BUILD_SHARED_LIBS) | ||
| set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
| endif() | ||
|
|
||
| add_library(${CMAKE_PROJECT_NAME} src/whereami.c src/whereami.h) | ||
| target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) | ||
| set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY C_STANDARD 99) | ||
|
|
||
| include(GNUInstallDirs) | ||
| install(TARGETS ${CMAKE_PROJECT_NAME}) | ||
| install(FILES src/whereami.h DESTINATION include) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "slices" | ||
| "strings" | ||
| ) | ||
|
|
||
| const consumerSource = `#include <whereami.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| int main(void) { | ||
| int length = wai_getExecutablePath(NULL, 0, NULL); | ||
| if (length <= 0) { | ||
| return 1; | ||
| } | ||
|
|
||
| char* path = (char*)malloc((size_t)length + 1); | ||
| if (!path) { | ||
| return 1; | ||
| } | ||
|
|
||
| int dirname_length = 0; | ||
| if (wai_getExecutablePath(path, length, &dirname_length) != length) { | ||
| free(path); | ||
| return 1; | ||
| } | ||
| path[length] = '\0'; | ||
| printf("Executable path: %s\n", path); | ||
|
|
||
| length = wai_getModulePath(NULL, 0, NULL); | ||
| if (length <= 0) { | ||
| free(path); | ||
| return 1; | ||
| } | ||
| free(path); | ||
| return 0; | ||
| } | ||
| ` | ||
|
|
||
| id "gpakosz/whereami" | ||
|
|
||
| fromVer "f15606a65908bb097e1887a08a40ae083e9a5c53" | ||
|
|
||
| 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("f15606a65908bb097e1887a08a40ae083e9a5c53/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 "CMAKE_INSTALL_LIBDIR", "lib" | ||
| c.defineBool "BUILD_SHARED_LIBS", shared | ||
| c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC | ||
| c.configure | ||
| c.build | ||
| c.install | ||
|
|
||
| licenseDir := filepath.join(installDir, "licenses") | ||
| os.mkdirAll(licenseDir, 0o755)! | ||
| for name in []string{"LICENSE.MIT", "LICENSE.WTFPLv2"} { | ||
| license := os.readFile(filepath.join(ctx.SourceDir, name))! | ||
| os.writeFile(filepath.join(licenseDir, name), license, 0o644)! | ||
| } | ||
|
|
||
| metadata := []string{ | ||
| "-I" + filepath.join(installDir, "include"), | ||
| "-L" + filepath.join(installDir, "lib"), | ||
| "-lwhereami", | ||
| } | ||
| ctx.setMetadata strings.join(metadata, " ") | ||
| } | ||
|
|
||
| onTest ctx => { | ||
| installDir := ctx.outputDir | ||
| testDir := filepath.join(ctx.SourceDir, "_llar_consumer") | ||
| testSource := filepath.join(testDir, "consumer.c") | ||
| testBuild := filepath.join(testDir, "_build") | ||
| binary := filepath.join(testBuild, "consumer") | ||
| os.mkdirAll(testDir, 0o755)! | ||
| os.writeFile(testSource, []byte(consumerSource), 0o644)! | ||
|
|
||
| args := []string{ | ||
| testSource, | ||
| "-I" + filepath.join(installDir, "include"), | ||
| "-L" + filepath.join(installDir, "lib"), | ||
| "-lwhereami", | ||
| "-o", binary, | ||
| } | ||
| exec "cc", 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
+114
to
+115
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 |
||
| } | ||
| exec binary | ||
| lastErr! | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "gpakosz/whereami", | ||
| "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.
The
wai_getModulePathblock only queries the length and then discards it — the module path is never retrieved into a buffer and never printed, andpathwas already fully used above. As written it reads like dead/leftover logic. If the intent is to exercise both APIs, allocate + fill +printfthe module path (mirroring the executable-path block); otherwise, dropping this block would make the test's intent clearer.