From efc7f9a1fa6f470b8f0998b13b605576b01fa08c Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Tue, 18 Aug 2026 19:21:33 +0800 Subject: [PATCH 1/4] feat(tgc): add LLAR formula --- .../CMakeLists.txt | 13 +++ .../tgc_llar.gox | 107 ++++++++++++++++++ orangeduck/tgc/versions.json | 4 + 3 files changed, 124 insertions(+) create mode 100644 orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/CMakeLists.txt create mode 100644 orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/tgc_llar.gox create mode 100644 orangeduck/tgc/versions.json diff --git a/orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/CMakeLists.txt b/orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/CMakeLists.txt new file mode 100644 index 0000000..d9859c1 --- /dev/null +++ b/orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.15) +project(tgc LANGUAGES C) + +add_library(tgc ${TGC_SRC_DIR}/tgc.c) +set_property(TARGET tgc PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + +include(GNUInstallDirs) +install(TARGETS tgc + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +install(FILES ${TGC_SRC_DIR}/tgc.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/tgc_llar.gox b/orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/tgc_llar.gox new file mode 100644 index 0000000..4a8d494 --- /dev/null +++ b/orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/tgc_llar.gox @@ -0,0 +1,107 @@ +import ( + "os" + "path/filepath" + "slices" + "strings" +) + +const consumerSource = `#include + +static tgc_t gc; + +static void example_function() { + char *message = tgc_alloc(&gc, 64); + strcpy(message, "No More Memory Leaks!"); +} + +int main(int argc, char **argv) { + tgc_start(&gc, &argc); + + example_function(); + + tgc_stop(&gc); + + return 0; +} +` + +id "orangeduck/tgc" + +fromVer "e193133e43af0862f51edfb9b518e212ea084412" + +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 + + cmakeLists := ctx.Proj.readFile("e193133e43af0862f51edfb9b518e212ea084412/CMakeLists.txt")! + os.writeFile(filepath.join(ctx.SourceDir, "CMakeLists.txt"), cmakeLists, 0o644)! + + shared := slices.contains(target.options["shared"], "ON") + fPIC := slices.contains(target.options["fPIC"], "ON") + c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) + c.define "TGC_SRC_DIR", ctx.SourceDir + c.defineBool "BUILD_SHARED_LIBS", shared + if !shared { + 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.md"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE.md"))!, 0o644)! + + metadata := []string{ + "-I" + filepath.join(installDir, "include"), + "-L" + filepath.join(installDir, "lib"), + "-ltgc", + } + ctx.setMetadata strings.join(metadata, " ") +} + +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)! + + shared := slices.contains(target.options["shared"], "ON") + binary := filepath.join(testDir, "consumer") + args := []string{ + consumer, + "-I" + filepath.join(installDir, "include"), + "-L" + filepath.join(installDir, "lib"), + "-ltgc", + "-o", binary, + } + 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! +} diff --git a/orangeduck/tgc/versions.json b/orangeduck/tgc/versions.json new file mode 100644 index 0000000..641a614 --- /dev/null +++ b/orangeduck/tgc/versions.json @@ -0,0 +1,4 @@ +{ + "path": "orangeduck/tgc", + "deps": {} +} From 9d46fe1c15940014063a6f37a6aea1fa2ae5a341 Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Wed, 19 Aug 2026 18:35:25 +0800 Subject: [PATCH 2/4] fix(tgc): publish relocatable pkg-config metadata --- .../tgc_llar.gox | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/tgc_llar.gox b/orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/tgc_llar.gox index 4a8d494..d1ad5ed 100644 --- a/orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/tgc_llar.gox +++ b/orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/tgc_llar.gox @@ -6,6 +6,7 @@ import ( ) const consumerSource = `#include +#include static tgc_t gc; @@ -58,8 +59,12 @@ onBuild ctx => { fPIC := slices.contains(target.options["fPIC"], "ON") c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) c.define "TGC_SRC_DIR", ctx.SourceDir + // Keep the installed library directory stable across platforms; GNUInstallDirs + // otherwise selects lib64 on some 64-bit systems. + c.define "CMAKE_INSTALL_LIBDIR", "lib" c.defineBool "BUILD_SHARED_LIBS", shared if !shared { + // The Conan recipe enables PIC for static builds only. c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC } c.configure @@ -70,12 +75,24 @@ onBuild ctx => { os.mkdirAll(licenseDir, 0o755)! os.writeFile(filepath.join(licenseDir, "LICENSE.md"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE.md"))!, 0o644)! - metadata := []string{ - "-I" + filepath.join(installDir, "include"), - "-L" + filepath.join(installDir, "lib"), - "-ltgc", - } - ctx.setMetadata strings.join(metadata, " ") + // The upstream commit has no build files or pkg-config metadata, so this + // formula supplies the install recipe and a relocatable consumer interface. + pkgconfigDir := filepath.join(installDir, "lib", "pkgconfig") + os.mkdirAll(pkgconfigDir, 0o755)! + pc := `prefix=$${pcfiledir}/../.. +includedir=$${prefix}/include +libdir=$${prefix}/lib + +Name: tgc +Description: Tiny garbage collector for C +Version: e193133e43af0862f51edfb9b518e212ea084412 +Cflags: -I$${includedir} +Libs: -L$${libdir} -ltgc +` + os.writeFile(filepath.join(pkgconfigDir, "tgc.pc"), []byte(pc), 0o644)! + + pkgconfig.use installDir + ctx.setMetadata pkgconfig.lookup("tgc")! } onTest ctx => { @@ -86,22 +103,19 @@ onTest ctx => { consumer := filepath.join(testDir, "consumer.c") os.writeFile(consumer, []byte(consumerSource), 0o644)! - shared := slices.contains(target.options["shared"], "ON") binary := filepath.join(testDir, "consumer") - args := []string{ - consumer, - "-I" + filepath.join(installDir, "include"), - "-L" + filepath.join(installDir, "lib"), - "-ltgc", - "-o", binary, - } - exec "cc", args... - lastErr! + pkgconfig.use installDir + flags := strings.fields(pkgconfig.lookup("tgc")!) + args := []string{consumer} + args <- flags... + args <- "-o", binary + cc! args... + + shared := slices.contains(target.options["shared"], "ON") if shared { os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! } - exec binary - lastErr! + exec! binary } From 7ca3ef537c6e6b44056615203ed30e40782855ff Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Wed, 19 Aug 2026 19:07:17 +0800 Subject: [PATCH 3/4] fix(tgc): lower formula compatibility threshold --- .../CMakeLists.txt | 0 .../tgc_llar.gox | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) rename orangeduck/tgc/{e193133e43af0862f51edfb9b518e212ea084412 => 05354008dc0de09e0a076647b8a678aaebfa58e6}/CMakeLists.txt (100%) rename orangeduck/tgc/{e193133e43af0862f51edfb9b518e212ea084412 => 05354008dc0de09e0a076647b8a678aaebfa58e6}/tgc_llar.gox (93%) diff --git a/orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/CMakeLists.txt b/orangeduck/tgc/05354008dc0de09e0a076647b8a678aaebfa58e6/CMakeLists.txt similarity index 100% rename from orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/CMakeLists.txt rename to orangeduck/tgc/05354008dc0de09e0a076647b8a678aaebfa58e6/CMakeLists.txt diff --git a/orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/tgc_llar.gox b/orangeduck/tgc/05354008dc0de09e0a076647b8a678aaebfa58e6/tgc_llar.gox similarity index 93% rename from orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/tgc_llar.gox rename to orangeduck/tgc/05354008dc0de09e0a076647b8a678aaebfa58e6/tgc_llar.gox index d1ad5ed..60d6c11 100644 --- a/orangeduck/tgc/e193133e43af0862f51edfb9b518e212ea084412/tgc_llar.gox +++ b/orangeduck/tgc/05354008dc0de09e0a076647b8a678aaebfa58e6/tgc_llar.gox @@ -28,7 +28,7 @@ int main(int argc, char **argv) { id "orangeduck/tgc" -fromVer "e193133e43af0862f51edfb9b518e212ea084412" +fromVer "05354008dc0de09e0a076647b8a678aaebfa58e6" defaults { "shared": "OFF", @@ -52,7 +52,7 @@ filter => { onBuild ctx => { installDir := ctx.outputDir - cmakeLists := ctx.Proj.readFile("e193133e43af0862f51edfb9b518e212ea084412/CMakeLists.txt")! + cmakeLists := ctx.Proj.readFile("05354008dc0de09e0a076647b8a678aaebfa58e6/CMakeLists.txt")! os.writeFile(filepath.join(ctx.SourceDir, "CMakeLists.txt"), cmakeLists, 0o644)! shared := slices.contains(target.options["shared"], "ON") @@ -85,7 +85,7 @@ libdir=$${prefix}/lib Name: tgc Description: Tiny garbage collector for C -Version: e193133e43af0862f51edfb9b518e212ea084412 +Version: 0.1.0 Cflags: -I$${includedir} Libs: -L$${libdir} -ltgc ` From 1ede57937562fc0d7659fbbc2146b524963680e9 Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Wed, 19 Aug 2026 19:56:53 +0800 Subject: [PATCH 4/4] style(tgc): use XGo string fields property --- .../tgc/05354008dc0de09e0a076647b8a678aaebfa58e6/tgc_llar.gox | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/orangeduck/tgc/05354008dc0de09e0a076647b8a678aaebfa58e6/tgc_llar.gox b/orangeduck/tgc/05354008dc0de09e0a076647b8a678aaebfa58e6/tgc_llar.gox index 60d6c11..afec0d0 100644 --- a/orangeduck/tgc/05354008dc0de09e0a076647b8a678aaebfa58e6/tgc_llar.gox +++ b/orangeduck/tgc/05354008dc0de09e0a076647b8a678aaebfa58e6/tgc_llar.gox @@ -2,7 +2,6 @@ import ( "os" "path/filepath" "slices" - "strings" ) const consumerSource = `#include @@ -106,7 +105,7 @@ onTest ctx => { binary := filepath.join(testDir, "consumer") pkgconfig.use installDir - flags := strings.fields(pkgconfig.lookup("tgc")!) + flags := pkgconfig.lookup("tgc")!.fields args := []string{consumer} args <- flags... args <- "-o", binary