-
Notifications
You must be signed in to change notification settings - Fork 2
formula: mutouyun/cpp-ipc #193
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,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) | ||
| 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") { | ||
|
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. [P3] Redundant second read of CMakeLists.txt The file is read into |
||
| if line.hasPrefix("project(cpp-ipc VERSION ") { | ||
| version = line.trimPrefix("project(cpp-ipc VERSION ").trimSuffix(")") | ||
|
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. [P3] Version parse via trimSuffix is fragile vs .split(")")[0]
|
||
| break | ||
| } | ||
| } | ||
| if version == "" { | ||
| panic "cpp-ipc CMakeLists.txt has no project version" | ||
| } | ||
|
|
||
| libs := "-L$${libdir} -lipc" | ||
| if target.require["os"][0] == "linux" { | ||
|
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. [P2] Unguarded target.require["os"][0] can panic; use slices.contains This is the only recipe in the repo that indexes |
||
| libs += " -lrt -lpthread -lm" | ||
|
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. [P3] -lm is not linked by upstream cpp-ipc Upstream |
||
| } | ||
| 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 | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "mutouyun/cpp-ipc", | ||
| "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.
[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,replacesilently matches nothing and the hardcoded PIC stays — quietly breaking thefPIC=OFFstatic build with no error. Thedouble-conversionreference guards its replace with a.containscheck. Consider a guard (and ideallypanicon mismatch) so future drift surfaces loudly.