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
122 changes: 122 additions & 0 deletions mborgerding/kissfft/131.1.0/kissfft_llar.gox
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import (
"os"
"path/filepath"
"slices"
"strings"
)

const consumerSource = `#include <kiss_fft.h>

#include <stdio.h>

int main()
{
printf("kiss_fft_next_fast_size(1) = %i\n", kiss_fft_next_fast_size(1));
return 0;
}
`

id "mborgerding/kissfft"

fromVer "131.1.0"

defaults {
"shared": "OFF",
"fPIC": "ON",
"datatype": "float",
"openmp": "OFF",
"use_alloca": "OFF",
}

filter => {
datatypes := ["float", "double", "int16_t", "int32_t", "simd"]
for name, values in target.options {
switch name {
case "shared", "fPIC", "openmp", "use_alloca":
for value in values {
if value != "ON" && value != "OFF" {
return false
}
}
case "datatype":
for value in values {
if !slices.contains(datatypes, value) {
return false
}
}
default:
return false
}
}
return true
}

onBuild ctx => {
installDir := ctx.outputDir
shared := slices.contains(target.options["shared"], "ON")
fPIC := slices.contains(target.options["fPIC"], "ON")
openmp := slices.contains(target.options["openmp"], "ON")
useAlloca := slices.contains(target.options["use_alloca"], "ON")
datatype := target.options["datatype"][0]

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.

Multi-value options can silently mis-build. filter iterates over all values per option and only rejects when some value is invalid, so it accepts targets that pass multiple values for one option (e.g. datatype: ["float", "double"] or shared: ["ON", "OFF"]). But onBuild collapses those inconsistently: the booleans (lines 56-59) use slices.contains(..., "ON") (ON wins), while datatype here uses [0] (first value wins, rest discarded). A target requesting two datatypes would pass filter, build only the first, and produce a package that doesn't match the requested options.

Simplest fix: reject multi-value options in filter, e.g. if values.len != 1 { return false } inside the loop, since each of these options is logically single-valued. That also removes the mixed slices.contains vs [0] idiom.


c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir)
c.define "CMAKE_INSTALL_LIBDIR", "lib"
c.define "CMAKE_INSTALL_INCLUDEDIR", "include"
c.define "KISSFFT_DATATYPE", datatype
c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC
c.defineBool "KISSFFT_PKGCONFIG", true
c.defineBool "KISSFFT_STATIC", !shared
c.defineBool "KISSFFT_TEST", false
c.defineBool "KISSFFT_TOOLS", false
c.defineBool "KISSFFT_OPENMP", openmp
c.defineBool "KISSFFT_USE_ALLOCA", useAlloca
c.configure
c.build
c.install

licenseDir := filepath.join(installDir, "licenses")
os.mkdirAll(licenseDir, 0o755)!
os.writeFile(filepath.join(licenseDir, "COPYING"), os.readFile(filepath.join(ctx.SourceDir, "COPYING"))!, 0o644)!

pcName := "kissfft-" + datatype
if openmp {
pcName += "-openmp"
}

// CMake writes prefix from CMAKE_INSTALL_PREFIX. Keep the generated
// flags and make the installed file relocatable.
pcPath := filepath.join(installDir, "lib", "pkgconfig", pcName+".pc")
pc := string(os.readFile(pcPath)!)
pc = strings.replace(pc, "prefix="+installDir, "prefix=$${pcfiledir}/../..", 1)
os.writeFile(pcPath, []byte(pc), 0o644)!

pkgconfig.use installDir
ctx.setMetadata pkgconfig.lookup(pcName)!
}

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)!

pcName := "kissfft-" + target.options["datatype"][0]

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.

Minor: the pcName derivation ("kissfft-" + datatype plus optional -openmp) is duplicated here from onBuild (lines 81-84), and the two copies read the options differently (onBuild uses the local datatype/openmp vars; here it re-reads target.options[...] inline). They can drift if the upstream naming scheme changes. Likely unavoidable across the build/test handler boundary, but worth keeping the two sites in lock-step.

if slices.contains(target.options["openmp"], "ON") {
pcName += "-openmp"
}

pkgconfig.use installDir
flagsFile := filepath.join(testDir, "kissfft.flags")
os.writeFile(flagsFile, []byte(pkgconfig.lookup(pcName)!), 0o644)!

binary := filepath.join(testDir, "consumer")
cc! consumer, "-o", binary, "@"+flagsFile

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"))!
}
exec! binary
}
4 changes: 4 additions & 0 deletions mborgerding/kissfft/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "mborgerding/kissfft",
"deps": {}
}
Loading