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
108 changes: 108 additions & 0 deletions danfis/libccd/v2.1/ccd_llar.gox
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import (
"os"
"path/filepath"
"slices"
"strings"
)

const consumerSource = `#include <ccd/ccd.h>

int main(void) {
ccd_t ccd;
CCD_INIT(&ccd);

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 consumer test only uses CCD_INIT, which is a header-only macro (field initialization). It compiles and links even if the libccd library itself fails to link, so it doesn't validate the Libs:/-lm/CCD_STATIC_DEFINE flags this recipe adds in onBuild. Peer consumers call a real exported function to force a link (e.g. de265_new_decoder in libde265, crc32c::Crc32c in crc32c). Consider calling an actual exported symbol such as ccdVec3Dist2 so the test exercises the link.

return 0;
}
`

id "danfis/libccd"

fromVer "v2.1"

defaults {
"shared": "OFF",
"fPIC": "ON",
"enable_double_precision": "OFF",
}

filter => {
for name, values in target.options {
if name != "shared" && name != "fPIC" && name != "enable_double_precision" {
return false
}
for value in values {
if value != "ON" && value != "OFF" {
return false
}
}
}
return true
}

onBuild ctx => {
installDir := ctx.outputDir
shared := target.options["shared"][0] == "ON"

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 filter (lines 27-39) iterates for value in values, so it accepts targets that carry multiple values for an option (e.g. shared=[ON, OFF]), rejecting only unknown names/values. But onBuild/onTest read only [0] and silently ignore the rest, so a passing multi-value target would build one arbitrary variant. Peer recipes with this same filter shape use membership instead of position: slices.contains(target.options["shared"], "ON") (see libdeflate, neco). slices is already imported. Either switch to slices.contains or tighten the filter to require single-valued options. Same [0] pattern recurs at line 103.

fPIC := target.options["fPIC"][0] == "ON"
enableDoublePrecision := target.options["enable_double_precision"][0] == "ON"

c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir)
c.define "CMAKE_INSTALL_LIBDIR", "lib"
c.define "CMAKE_POLICY_VERSION_MINIMUM", "3.5"
c.defineBool "BUILD_DOCUMENTATION", false
c.defineBool "BUILD_SHARED_LIBS", shared
c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC
c.defineBool "ENABLE_DOUBLE_PRECISION", enableDoublePrecision
c.defineBool "CCD_HIDE_ALL_SYMBOLS", !shared
c.configure
c.build
c.install

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

// Upstream installs ccd.pc with CMAKE_INSTALL_PREFIX-expanded paths.
// Keep its verified flags while making the installed metadata relocatable.

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.

This comment describes only the prefix relocation, but the code below also augments upstream flags for static builds — appending -DCCD_STATIC_DEFINE to Cflags: (74-75) and -lm to Libs: (77-78). "Keep its verified flags" understates that. Relatedly, CCD_HIDE_ALL_SYMBOLS = !shared (line 54) is uncommented despite being coupled to the -DCCD_STATIC_DEFINE re-add (upstream injects it at build time only, so a static consumer must define it too, or hit visibility/dllimport mismatches). The sibling libde265 recipe comments its non-obvious CMake tweaks; a brief note on why -DCCD_STATIC_DEFINE/-lm are added for static builds would help future maintainers.

pcPath := filepath.join(installDir, "lib", "pkgconfig", "ccd.pc")
pc := string(os.readFile(pcPath)!)
pc = strings.replace(pc, "prefix="+installDir, "prefix=$${pcfiledir}/../..", 1)
pc = strings.replace(pc, "exec_prefix="+installDir, "exec_prefix=$${prefix}", 1)
pc = strings.replace(pc, "libdir="+filepath.join(installDir, "lib"), "libdir=$${prefix}/lib", 1)
pc = strings.replace(pc, "includedir="+filepath.join(installDir, "include"), "includedir=$${prefix}/include", 1)
lines := pc.split("\n")
if !shared {
for i, line in lines {
if line.hasPrefix("Cflags:") && !strings.contains(line, "CCD_STATIC_DEFINE") {
lines[i] = line + " -DCCD_STATIC_DEFINE"
}
if slices.contains(target.require["os"], "linux") && line.hasPrefix("Libs:") && !strings.contains(line, " -lm") {

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.

-lm is appended only when require["os"] contains linux, but libccd's static build needs libm on other non-Windows platforms too (e.g. freebsd, which this repo targets in neco). If macOS/BSD targets are in scope, the static consumer link could fail. If libccd is intentionally linux-only for now, consider gating with !windows (as microtar does) or documenting the platform restriction so the assumption is explicit.

lines[i] = line + " -lm"
}
}
}
os.writeFile(pcPath, []byte(strings.join(lines, "\n")), 0o644)!

pkgconfig.use installDir
ctx.setMetadata pkgconfig.lookup("ccd")!
}

onTest ctx => {
installDir := ctx.outputDir
testDir := filepath.join(ctx.SourceDir, "_llar_consumer")
os.mkdirAll(testDir, 0o755)!

sourcePath := filepath.join(testDir, "consumer.c")
os.writeFile(sourcePath, []byte(consumerSource), 0o644)!

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

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

if target.options["shared"][0] == "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 danfis/libccd/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "danfis/libccd",
"deps": {}
}
Loading