-
Notifications
You must be signed in to change notification settings - Fork 2
feat(iqa): add LLAR formula #147
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,143 @@ | ||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "runtime" | ||
| "slices" | ||
| "strings" | ||
| ) | ||
|
|
||
| const cmakeLists = `cmake_minimum_required(VERSION 3.12) | ||
| project(iqa C) | ||
|
|
||
| if(MSVC AND BUILD_SHARED_LIBS) | ||
| set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
| endif() | ||
|
|
||
| file(GLOB IQA_SOURCES $${IQA_SRC_DIR}/source/*.c) | ||
| file(GLOB IQA_HEADERS $${IQA_SRC_DIR}/include/*.h) | ||
|
|
||
| add_library(iqa $${IQA_SOURCES}) | ||
| target_include_directories(iqa PUBLIC $${IQA_SRC_DIR}/include) | ||
|
|
||
| include(GNUInstallDirs) | ||
| install(TARGETS iqa | ||
| RUNTIME DESTINATION $${CMAKE_INSTALL_BINDIR} | ||
| LIBRARY DESTINATION $${CMAKE_INSTALL_LIBDIR} | ||
| ARCHIVE DESTINATION $${CMAKE_INSTALL_LIBDIR}) | ||
| install(FILES $${IQA_HEADERS} DESTINATION $${CMAKE_INSTALL_INCLUDEDIR}) | ||
| ` | ||
|
|
||
| const consumerSource = `#include "math_utils.h" | ||
|
|
||
| int main(void) { | ||
| _max(0, 1); | ||
| return 0; | ||
| } | ||
| ` | ||
|
|
||
| id "tjdistler/iqa" | ||
|
|
||
| fromVer "0559a8ff2acd9746864975834d35be6892cc9801" | ||
|
|
||
| defaults { | ||
| "shared": "OFF", | ||
| "fPIC": "ON", | ||
| } | ||
|
Comment on lines
+42
to
+45
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] Missing build-contract / options documentation vs sibling formulas The sibling formulas ( |
||
|
|
||
| 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 | ||
| projectDir := filepath.join(ctx.SourceDir, "_llar_cmake") | ||
| os.mkdirAll(projectDir, 0o755)! | ||
| os.writeFile(filepath.join(projectDir, "CMakeLists.txt"), []byte(cmakeLists), 0o644)! | ||
|
|
||
| shared := slices.contains(target.options["shared"], "ON") | ||
| fPIC := slices.contains(target.options["fPIC"], "ON") | ||
| c := cmake.new(projectDir, filepath.join(ctx.SourceDir, "_build"), installDir) | ||
| c.define "IQA_SRC_DIR", ctx.SourceDir | ||
| c.defineBool "BUILD_SHARED_LIBS", shared | ||
| if !shared { | ||
| c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC | ||
| } | ||
| c.configure | ||
| c.build | ||
| c.install | ||
|
|
||
| license := string(os.readFile(filepath.join(ctx.SourceDir, "include", "iqa.h"))!) | ||
| licenseEnd := strings.index(license, "*/") | ||
| license = strings.trimSpace(license[:licenseEnd]) | ||
|
Comment on lines
+80
to
+81
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] License parse can slice with a negative index when
Minor, in the same block: the |
||
| license = strings.replace(license, "/*", "", 1) | ||
| license = strings.replace(license, "\n * ", "\n", -1) | ||
| licenseDir := filepath.join(installDir, "licenses") | ||
| os.mkdirAll(licenseDir, 0o755)! | ||
| os.writeFile(filepath.join(licenseDir, "LICENSE"), []byte(license), 0o644)! | ||
|
|
||
| osName := runtime.GOOS | ||
| osValues := target.require["os"] | ||
| if osValues.len > 0 { | ||
| osName = osValues[0] | ||
| } | ||
| flags := []string{ | ||
| "-I" + filepath.join(installDir, "include"), | ||
| "-L" + filepath.join(installDir, "lib"), | ||
| "-liqa", | ||
| } | ||
| if osName == "linux" { | ||
| flags <- "-lm" | ||
| } | ||
|
Comment on lines
+98
to
+100
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]
|
||
| ctx.setMetadata strings.join(flags, " ") | ||
| } | ||
|
|
||
| onTest ctx => { | ||
| installDir := ctx.outputDir | ||
| testDir := filepath.join(ctx.SourceDir, "_llar_consumer") | ||
| os.mkdirAll(testDir, 0o755)! | ||
|
|
||
| consumer := filepath.join(testDir, "consumer.c") | ||
| os.writeFile(consumer, []byte(consumerSource), 0o644)! | ||
|
|
||
| osName := runtime.GOOS | ||
| osValues := target.require["os"] | ||
| if osValues.len > 0 { | ||
| osName = osValues[0] | ||
| } | ||
| shared := slices.contains(target.options["shared"], "ON") | ||
| binary := filepath.join(testDir, "consumer") | ||
| args := []string{ | ||
| consumer, | ||
| "-I" + filepath.join(installDir, "include"), | ||
| "-L" + filepath.join(installDir, "lib"), | ||
| "-liqa", | ||
| } | ||
| if osName == "linux" { | ||
| args <- "-lm" | ||
| } | ||
| args <- "-o", binary | ||
| exec "cc", args... | ||
| lastErr! | ||
|
|
||
| if shared { | ||
| if osName == "windows" { | ||
| path := os.getenv("PATH") | ||
| os.setenv("PATH", filepath.join(installDir, "bin")+";"+path)! | ||
| } else { | ||
| os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
|
Comment on lines
+137
to
+138
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] The Windows branch prepends to the existing |
||
| } | ||
| } | ||
| exec binary | ||
| lastErr! | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "tjdistler/iqa", | ||
| "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.
[P3] Filename
iqa_llar.goxdiffers from PascalCase siblingsSibling formulas use a capitalized project prefix:
Cglm_llar.gox,Jsonc_llar.gox,Zlib_llar.gox. This file is lowercaseiqa_llar.gox. If the loader is case-sensitive about the prefix, rename toIqa_llar.goxfor consistency; otherwise confirm lowercase is accepted.