-
Notifications
You must be signed in to change notification settings - Fork 2
feat(kissfft): add LLAR formula #174
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,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] | ||
|
|
||
| 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] | ||
|
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. Minor: the |
||
| 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 | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "mborgerding/kissfft", | ||
| "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.
Multi-value options can silently mis-build.
filteriterates over allvaluesper 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"]orshared: ["ON", "OFF"]). ButonBuildcollapses those inconsistently: the booleans (lines 56-59) useslices.contains(..., "ON")(ON wins), whiledatatypehere uses[0](first value wins, rest discarded). A target requesting two datatypes would passfilter, 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 mixedslices.containsvs[0]idiom.