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
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;
Comment on lines +31 to +37

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.

The wai_getModulePath block only queries the length and then discards it — the module path is never retrieved into a buffer and never printed, and path was already fully used above. As written it reads like dead/leftover logic. If the intent is to exercise both APIs, allocate + fill + printf the module path (mirroring the executable-path block); otherwise, dropping this block would make the test's intent clearer.

}
`

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

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.

These setenv calls overwrite any existing LD_LIBRARY_PATH/DYLD_LIBRARY_PATH rather than prepending. For the shared-lib test that's usually fine (the injected path is trusted installDir/lib), but if the test binary relies on other shared libs resolved via a pre-set value, this could break/flake. Consider prepending the prior value, e.g. installLib + ":" + os.getenv("LD_LIBRARY_PATH"). Low priority.

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