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
124 changes: 124 additions & 0 deletions mutouyun/cpp-ipc/v1.4.1/cppipc_llar.gox
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import (
"os"
"path/filepath"
"strings"
)

const consumerSource = `#include <cstdlib>
#include "libipc/ipc.h"

int main() {
ipc::channel cc{"my-ipc-channel", ipc::sender | ipc::receiver};
return EXIT_SUCCESS;
}
`

id "mutouyun/cpp-ipc"

fromVer "v1.4.1"

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

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
shared := target.options["shared"][0] == "ON"
fPIC := target.options["fPIC"][0] == "ON"

// Upstream hardcodes PIC ON; drop that assignment so the fPIC option
// controls CMAKE_POSITION_INDEPENDENT_CODE for static builds.
cmakeLists := filepath.join(ctx.SourceDir, "CMakeLists.txt")
source := string(os.readFile(cmakeLists)!)
source = strings.replace(source, "set(CMAKE_POSITION_INDEPENDENT_CODE ON)\n", "", 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.

[P3] Unguarded string.replace can silently no-op on upstream drift

The PIC-line removal at line 48 matches the exact literal set(CMAKE_POSITION_INDEPENDENT_CODE ON)\n (verified present in v1.4.1 today, so it works now). But if upstream ever changes spacing/casing/line-ending, replace silently matches nothing and the hardcoded PIC stays — quietly breaking the fPIC=OFF static build with no error. The double-conversion reference guards its replace with a .contains check. Consider a guard (and ideally panic on mismatch) so future drift surfaces loudly.

os.writeFile(cmakeLists, []byte(source), 0o644)!

c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir)
c.define "CMAKE_POLICY_VERSION_MINIMUM", "3.5"
c.defineBool "LIBIPC_BUILD_SHARED_LIBS", shared
c.defineBool "LIBIPC_BUILD_TESTS", false
c.defineBool "LIBIPC_BUILD_DEMOS", false
c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC
c.configure
c.build
c.install

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

version := ""
for line in strings.split(string(os.readFile(cmakeLists)!), "\n") {

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.

[P3] Redundant second read of CMakeLists.txt

The file is read into source at line 47, then read from disk again at line 66 for version parsing. The PIC replace at line 48 doesn't touch the project(...) line, so you can parse the version from the in-memory source (strings.split(source, "\n")) and drop the redundant read.

if line.hasPrefix("project(cpp-ipc VERSION ") {
version = line.trimPrefix("project(cpp-ipc VERSION ").trimSuffix(")")

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.

[P3] Version parse via trimSuffix is fragile vs .split(")")[0]

trimSuffix(")") yields the wrong value if upstream adds tokens after the version, e.g. project(cpp-ipc VERSION 1.4.1 LANGUAGES CXX)1.4.1 LANGUAGES CXX. The double-conversion reference uses .split(")")[0], which is resilient to trailing tokens. Consider matching that pattern.

break
}
}
if version == "" {
panic "cpp-ipc CMakeLists.txt has no project version"
}

libs := "-L$${libdir} -lipc"
if target.require["os"][0] == "linux" {

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.

[P2] Unguarded target.require["os"][0] can panic; use slices.contains

This is the only recipe in the repo that indexes target.require["os"][0] directly — microtar, neco use slices.contains(target.require["os"], ...) and poshlib guards with a length check. If os is empty/unset, [0] panics with index-out-of-range. Prefer slices.contains(target.require["os"], "linux") for consistency and safety.

libs += " -lrt -lpthread -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.

[P3] -lm is not linked by upstream cpp-ipc

Upstream src/CMakeLists.txt links only pthread and rt (PUBLIC pthread rt) on Linux — the math library m is never linked. The added -lm overstates the library's dependencies in the generated .pc. It is likely harmless (no-op on most linkers), but consider dropping it to match upstream, or add a comment if there is a real reason.

}
cflags := "-I$${includedir}"
if shared {
cflags += " -DLIBIPC_LIBRARY_SHARED_USING__"
}

pcDir := filepath.join(installDir, "lib", "pkgconfig")
os.mkdirAll(pcDir, 0o755)!
pc := `prefix=$${pcfiledir}/../..
exec_prefix=$${prefix}
libdir=$${prefix}/lib
includedir=$${prefix}/include

Name: ipc
Description: C++ IPC Library
Version: ` + version + `
Libs: ` + libs + `
Cflags: ` + cflags + `
`
os.writeFile(filepath.join(pcDir, "ipc.pc"), []byte(pc), 0o644)!

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

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

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

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

binary := filepath.join(testDir, "consumer")
exec! "c++", "-std=c++17", consumer, "-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 mutouyun/cpp-ipc/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "mutouyun/cpp-ipc",
"deps": {}
}
Loading