From 042c727c096bce96120ede4a71a33d8414b54598 Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Tue, 18 Aug 2026 16:44:07 +0800 Subject: [PATCH] feat: add ChaiScript formula --- ChaiScript/ChaiScript/chaiscript_cmp.gox | 23 +++++ .../ChaiScript/v5.0.0/chaiscript_llar.gox | 91 +++++++++++++++++++ ChaiScript/ChaiScript/versions.json | 4 + 3 files changed, 118 insertions(+) create mode 100644 ChaiScript/ChaiScript/chaiscript_cmp.gox create mode 100644 ChaiScript/ChaiScript/v5.0.0/chaiscript_llar.gox create mode 100644 ChaiScript/ChaiScript/versions.json diff --git a/ChaiScript/ChaiScript/chaiscript_cmp.gox b/ChaiScript/ChaiScript/chaiscript_cmp.gox new file mode 100644 index 0000000..80e2176 --- /dev/null +++ b/ChaiScript/ChaiScript/chaiscript_cmp.gox @@ -0,0 +1,23 @@ +import "strings" + +// Stable releases use v-prefixed semantic versions, while the repository +// also keeps Release-* aliases and two named snapshots. The snapshots are +// mapped to their source-tree release lines so every visible tag is accepted +// without letting the WebAssembly-only snapshot become the default native +// build. +func normalize(version string) string { + if strings.hasPrefix(version, "Release-") { + return "v" + strings.trimPrefix(version, "Release-") + } + if version == "Test_Release" { + return "v5.7.2" + } + if version == "wasm-latest" { + return "v6.1.0-0" + } + return version +} + +compareVer (a, b) => { + return semver.Compare(normalize(a.Version), normalize(b.Version)) +} diff --git a/ChaiScript/ChaiScript/v5.0.0/chaiscript_llar.gox b/ChaiScript/ChaiScript/v5.0.0/chaiscript_llar.gox new file mode 100644 index 0000000..a7831b4 --- /dev/null +++ b/ChaiScript/ChaiScript/v5.0.0/chaiscript_llar.gox @@ -0,0 +1,91 @@ +import ( + "os" + "path/filepath" + "strings" +) + +const consumerSource = `#include +#include +#include + +double chai_add(double i, double j) +{ + return i + j; +} + +int main() +{ + chaiscript::ChaiScript chai({CHAI_MODULE_PATH}); + chai.add(chaiscript::fun(&chai_add), "add"); + const auto answer = chai.eval("add(38.8, 3.2);"); + assert(static_cast(answer) == 42); + std::cout << "The answer is: " << answer << '\n'; +} +` + +id "ChaiScript/ChaiScript" + +fromVer "v5.0.0" + +onBuild ctx => { + installDir := ctx.outputDir + + c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) + // The supported release line declares CMake 2.8; current CMake rejects + // that policy floor unless the minimum policy version is made explicit. + c.define "CMAKE_POLICY_VERSION_MINIMUM", "3.5" + c.defineBool "BUILD_TESTING", false + c.defineBool "BUILD_SAMPLES", false + c.defineBool "BUILD_MODULES", true + c.defineBool "MULTITHREAD_SUPPORT_ENABLED", true + c.configure + c.build + c.install + + // v5.0.0 builds the standard-library module but omits it from the CMake + // install target; the installed `chai` executable and consumers load it + // from lib/chaiscript at runtime. + stdlib := os.readFile(filepath.join(ctx.SourceDir, "_build", "libchaiscript_stdlib.so"))! + os.writeFile(filepath.join(installDir, "lib", "chaiscript", "libchaiscript_stdlib.so"), stdlib, 0o755)! + + // Keep the license published by the Conan package. + licenseDir := filepath.join(installDir, "licenses") + os.mkdirAll(licenseDir, 0o755)! + license := os.readFile(filepath.join(ctx.SourceDir, "license.txt"))! + os.writeFile(filepath.join(licenseDir, "license.txt"), license, 0o644)! + + // The upstream file embeds the build output path. Make it relocatable + // before using the installed pkg-config contract for Formula metadata. + pcPath := filepath.join(installDir, "lib", "pkgconfig", "chaiscript.pc") + pc := string(os.readFile(pcPath)!) + pc = strings.replace(pc, "prefix="+installDir, `prefix=$${pcfiledir}/../..`, 1) + os.writeFile(pcPath, []byte(pc), 0o644)! + + pkgconfig.use installDir + ctx.setMetadata pkgconfig.lookup("chaiscript")! +} + +onTest ctx => { + installDir := ctx.outputDir + testDir := filepath.join(ctx.SourceDir, "_llar_consumer") + os.mkdirAll(testDir, 0o755)! + + consumer := filepath.join(testDir, "consumer.cpp") + modulePath := "\"" + filepath.join(installDir, "lib", "chaiscript") + "/\"" + source := strings.replace(consumerSource, "CHAI_MODULE_PATH", modulePath, 1) + os.writeFile(consumer, []byte(source), 0o644)! + + // Resolve the complete installed cflags-and-libs query so this test checks + // the same metadata that downstream consumers receive, including on cache + // hits where onBuild is skipped. + pkgconfig.use installDir + flags := pkgconfig.lookup("chaiscript")! + flagsFile := filepath.join(testDir, "chaiscript.flags") + os.writeFile(flagsFile, []byte(flags), 0o644)! + + binary := filepath.join(testDir, "consumer") + exec "c++", "-std=c++17", "@"+flagsFile, consumer, "-o", binary + lastErr! + exec binary + lastErr! +} diff --git a/ChaiScript/ChaiScript/versions.json b/ChaiScript/ChaiScript/versions.json new file mode 100644 index 0000000..72a4742 --- /dev/null +++ b/ChaiScript/ChaiScript/versions.json @@ -0,0 +1,4 @@ +{ + "path": "ChaiScript/ChaiScript", + "deps": {} +}