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
134 changes: 134 additions & 0 deletions fast-pack/streamvbyte/v0.5.0/streamvbyte_llar.gox
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import (
"os"
"path/filepath"
"slices"
"strings"
)

const consumerProgram = `#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include "streamvbyte.h"

int main(void) {
uint32_t N = 100U;
uint32_t * datain = malloc(N * sizeof(uint32_t));
uint8_t * compressedbuffer = malloc(streamvbyte_max_compressedbytes(N));
uint32_t * recovdata = malloc(N * sizeof(uint32_t));
for (uint32_t k = 0; k < N; ++k)
datain[k] = 120;
size_t compsize = streamvbyte_encode(datain, N, compressedbuffer);
size_t compsize2 = streamvbyte_decode(compressedbuffer, recovdata, N);
assert(compsize == compsize2);
free(datain);
free(compressedbuffer);
free(recovdata);
printf("Compressed %d integers down to %d bytes.\n", N, (int) compsize);
return 0;
}
`

id "fast-pack/streamvbyte"

fromVer "v0.5.0"

defaults {
"shared": "OFF",
}

filter => {
for _, value in target.options["shared"] {
if value != "ON" && value != "OFF" {
return false
}
}
return true
}

onBuild ctx => {
installDir := ctx.outputDir
shared := slices.contains(target.options["shared"], "ON")

// Older tags explicitly disable macOS RPATH. Restore the relocatable
// setting when the shared option requires that installed library.
if shared {
content := string(ctx.Proj.readFile("CMakeLists.txt")!)
if strings.contains(content, "set(CMAKE_MACOSX_RPATH OFF)") {
patchPath := filepath.join(ctx.SourceDir, "_llar_macos_rpath.patch")
patchText := `--- CMakeLists.txt
+++ CMakeLists.txt
@@ -1,1 +1,1 @@

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 macOS RPATH patch will fail to apply — wrong hunk line number.

The hunk header hardcodes @@ -1,1 +1,1 @@, asserting set(CMAKE_MACOSX_RPATH OFF) is line 1 of CMakeLists.txt. Verified against upstream: at v0.5.0 line 1 is cmake_minimum_required(VERSION 3.3) and the RPATH setting is on line 2. With patch --batch --forward, the context won't match at line 1, so the hunk is rejected and lastErr! (line 67) then aborts the build — on exactly the macOS shared-build path this block is meant to support.

Since content is already read into memory (line 56), a simpler and robust fix is an in-memory replace instead of shelling out to patch:

content = strings.replaceAll(content, "set(CMAKE_MACOSX_RPATH OFF)", "set(CMAKE_MACOSX_RPATH ON)")
os.writeFile(filepath.join(ctx.SourceDir, "CMakeLists.txt"), []byte(content), 0o644)!

-set(CMAKE_MACOSX_RPATH OFF)
+set(CMAKE_MACOSX_RPATH ON)
`
os.writeFile(patchPath, []byte(patchText), 0o644)!
patch "--batch", "--forward", "-i", patchPath
lastErr!
}
}

c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir)
c.define "CMAKE_POLICY_VERSION_MINIMUM", "3.5"
c.defineBool "BUILD_SHARED_LIBS", shared
c.configure
c.build
c.install

// v0.5.0-v0.5.2 install the static target as
// libstreamvbyte_static.a; v0.5.3 and newer name it libstreamvbyte.a.
library := "streamvbyte"
if !shared {
_, err := os.stat(filepath.join(installDir, "lib", "libstreamvbyte.a"))

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.

lib is hardcoded, but v2.0.0/v3.0.0 install to ${CMAKE_INSTALL_LIBDIR} (often lib64).

Verified against upstream: v0.5.0v1.0.0 install with DESTINATION lib, but v2.0.0 and v3.0.0 include(GNUInstallDirs) and install with ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} (no override). On common 64-bit distros (Fedora/RHEL/openSUSE) that resolves to lib64.

Consequences on those platforms for v2.0.0/v3.0.0 — contradicting the PR's claimed v0.5.0–v3.0.0 range:

  • The os.stat(installDir/lib/libstreamvbyte.a) check (lines 82/109) fails, so the code silently falls back to library = "streamvbyte_static" — but streamvbyte_static hasn't existed as a target since v0.5.2, producing a wrong -lstreamvbyte_static flag.
  • The -L.../lib (lines 91/122) and LD_LIBRARY_PATH/DYLD_LIBRARY_PATH (lines 129/130) paths point at the wrong directory, so the consumer link/run fails.

Consider resolving the actual libdir (e.g. probe both lib and lib64, or set CMAKE_INSTALL_LIBDIR=lib explicitly in the cmake configure as json-c does) rather than assuming lib.

if os.isNotExist(err) {
library = "streamvbyte_static"
} else if err != nil {
panic err
}
}
flags := []string{
"-I" + filepath.join(installDir, "include"),
"-L" + filepath.join(installDir, "lib"),
"-l" + library,
}
ctx.setMetadata strings.join(flags, " ")
}

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(consumerProgram), 0o644)!

shared := slices.contains(target.options["shared"], "ON")
// Keep the cache-hit consumer aligned with the installed archive name.
library := "streamvbyte"

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.

Duplicated static-archive-name detection between onBuild and onTest.

The os.stat(libstreamvbyte.a) → fallback-to-streamvbyte_static block (lines 80–88) is repeated verbatim in onTest (lines 107–115). The two copies must stay in lockstep, and any fix to the detection (e.g. the lib64 issue above) has to be applied in both places. Extracting a small helper, e.g. staticLibName(installDir, shared), would remove the drift risk.

if !shared {
_, err := os.stat(filepath.join(installDir, "lib", "libstreamvbyte.a"))
if os.isNotExist(err) {
library = "streamvbyte_static"
} else if err != nil {
panic err
}
}

binary := filepath.join(testDir, "consumer")
args := []string{
sourcePath,
"-o", binary,
"-I" + filepath.join(installDir, "include"),
"-L" + filepath.join(installDir, "lib"),
"-l" + library,
}
exec "cc", args...
lastErr!

if shared {
os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))!
os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))!
}
exec binary
lastErr!
}
4 changes: 4 additions & 0 deletions fast-pack/streamvbyte/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "fast-pack/streamvbyte",

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.

versions.json uses 2-space indentation; the repo convention is tabs.

The three existing versions.json files (recp/cglm, madler/zlib, json-c/json-c) indent with a tab. Re-indent with tabs for consistency. (Related nit: this formula file is named streamvbyte_llar.gox lowercase, while the existing formulas are capitalized — Zlib_llar.gox, Cglm_llar.gox, Jsonc_llar.gox; rename to Streamvbyte_llar.gox unless the loader keys off the id directive rather than the filename.)

"deps": {}
}
Loading