From 45a1f7fadbe8c7e74ef5dc7a28ad535a39889c81 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Tue, 23 Sep 2025 01:49:04 +0800 Subject: [PATCH 1/9] fix: remove sensitive infomation --- scripts/sync.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/sync.py b/scripts/sync.py index 75f5a98..306eae4 100644 --- a/scripts/sync.py +++ b/scripts/sync.py @@ -145,7 +145,6 @@ def upload_releases( print(f"Failed to upload file: {response.text}") response.raise_for_status() print(f"Uploaded file: {file_name}") - print(f"Response: {response.text}") if __name__ == "__main__": @@ -161,6 +160,5 @@ def upload_releases( print(f"Version: {tag_name}") print(f"Target commitish: {target_commitish}") print(f"Title: {title}") - print(f"Body: {body}") upload_releases(release_dir, tag_name, target_commitish, title, body) From 5a8bb325c2d02dc5743e4d654aba229528cef5cd Mon Sep 17 00:00:00 2001 From: afocus Date: Thu, 25 Sep 2025 16:48:33 +0800 Subject: [PATCH 2/9] fix: extractCCSearchPaths for windows (#12) Co-authored-by: afocus --- src/clang/support.cj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/clang/support.cj b/src/clang/support.cj index 067a231..d670466 100644 --- a/src/clang/support.cj +++ b/src/clang/support.cj @@ -1,7 +1,7 @@ package cjbind.clang import std.fs.Path -import std.process.{executeWithOutput, ProcessRedirect} +import std.process.{launch, ProcessRedirect} import std.io.{readString, ByteBuffer} import std.collection.{collectArray, ArrayList, Map, HashMap} import std.posix.{access, isReg, X_OK} @@ -30,7 +30,8 @@ func isExecutable(path: String): Bool { func run(bin: String, args: Array, readStderr!: Bool = false, env!: Option> = None): ?String { try { - let (_, out, err) = executeWithOutput(bin, args, stdIn: ProcessRedirect.Discard, environment: env) + let p = launch(bin, args, stdIn: ProcessRedirect.Discard, environment: env) + let (_, out, err) = p.waitOutput() let buf = if (readStderr) { ByteBuffer(err) } else { From 8d9719fb23560466c0149f4a2e1f7d9570e77b11 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Fri, 10 Oct 2025 18:09:35 +0800 Subject: [PATCH 3/9] chore: bump to 1.0.3 --- .github/workflows/build.yml | 6 +++--- cjpm.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0127558..af16a5c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -79,9 +79,9 @@ jobs: channel: "lts" version: "auto" - - name: Patch Cangjie - run: | - uv run scripts/patch_opt.py + # - name: Patch Cangjie + # run: | + # uv run scripts/patch_opt.py - name: Setup MSYS2 if: matrix.os.sys == 'windows' diff --git a/cjpm.toml b/cjpm.toml index c6e0bae..25ee639 100644 --- a/cjpm.toml +++ b/cjpm.toml @@ -2,7 +2,7 @@ glob = { git = "https://github.com/Zxilly/glob-cj.git", tag = "v0.2.0" } [package] - cjc-version = "1.0.1" + cjc-version = "1.0.3" compile-option = "-Woff unused -V" description = "A simple C binding generator for Cangjie" link-option = "" From 36172096f1566ce5ab5b6545a2c483c20e776d72 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Fri, 10 Oct 2025 18:13:51 +0800 Subject: [PATCH 4/9] build: enable patch for 1.0.3 --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index af16a5c..0127558 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -79,9 +79,9 @@ jobs: channel: "lts" version: "auto" - # - name: Patch Cangjie - # run: | - # uv run scripts/patch_opt.py + - name: Patch Cangjie + run: | + uv run scripts/patch_opt.py - name: Setup MSYS2 if: matrix.os.sys == 'windows' From 61dddbf31498f2ab98883eeed0f31d18c701b086 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Mon, 20 Oct 2025 00:33:41 +0800 Subject: [PATCH 5/9] fix: workaround cangjie runtime error --- src/codegen/lib.cj | 3 ++- src/codegen/workaround.cj | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/codegen/workaround.cj diff --git a/src/codegen/lib.cj b/src/codegen/lib.cj index 3aef6bd..d7e4229 100644 --- a/src/codegen/lib.cj +++ b/src/codegen/lib.cj @@ -326,13 +326,14 @@ extend Var <: CodeGenerator { } case VarType.VarFloat(vv) => if (let Ok(expr) <- AstTy.floatExpr(ctx, vv)) { + let floatTokens = float64toTokens(vv) result .items .add( optionalComment( ctx, commentToken, - quote(public const $(canonicalIdent) : $(ty) = $(expr)) + quote(public const $(canonicalIdent) : $(ty) = $(floatTokens)) ) ) } diff --git a/src/codegen/workaround.cj b/src/codegen/workaround.cj new file mode 100644 index 0000000..5daf578 --- /dev/null +++ b/src/codegen/workaround.cj @@ -0,0 +1,22 @@ +package cjbind.codegen + +import std.ast.{Tokens, Token, TokenKind} + +foreign func CJ_AST_Float64ToCPointer(num: Float64): CString + +// workaround 仓颉标准库中有 bug 的 Float64 to Tokens 转换函数 +public func float64toTokens(val: Float64): Tokens { + let strPtr = unsafe { CJ_AST_Float64ToCPointer(val) } + var floatStr = String() + if (!strPtr.isNull()) { + floatStr = strPtr.toString() + unsafe { LibC.free(strPtr) } + } + floatStr = floatStr.replace("+", "") + + if (val < 0.0) { + return Tokens().append(Token(TokenKind.SUB)).append(Token(TokenKind.FLOAT_LITERAL, floatStr[1..])) + } + let tok: Token = Token(TokenKind.FLOAT_LITERAL, floatStr) + return tok.toTokens() +} \ No newline at end of file From 5b0c26bba2ab92a22a719b0e7a14e0f3b03f92d9 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Mon, 20 Oct 2025 00:43:14 +0800 Subject: [PATCH 6/9] fix: update version to 0.2.6 and add missing link options for targets --- cjpm.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cjpm.toml b/cjpm.toml index 25ee639..92cdb81 100644 --- a/cjpm.toml +++ b/cjpm.toml @@ -11,7 +11,7 @@ override-compile-option = "" src-dir = "" target-dir = "" - version = "0.2.5" + version = "0.2.6" [package.package-configuration."cjbind"] compile-option = "--link-options \"${LDFLAGS}\"" @@ -22,13 +22,16 @@ [target.x86_64-w64-mingw32.release] compile-option = "-O2" + link-option = "-l:libcangjie-std-ast.dll" [target.aarch64-apple-darwin.release] compile-option = "-O2" [target.x86_64-unknown-linux-gnu.release] compile-option = "-O2" + link-option = "-l:libcangjie-std-ast.so" [target.aarch64-unknown-linux-gnu.release] compile-option = "-O2" + link-option = "-l:libcangjie-std-ast.so" \ No newline at end of file From 06c28f1e51178d06ca456af6d09d850f64a6af71 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Mon, 20 Oct 2025 00:47:20 +0800 Subject: [PATCH 7/9] fix: update libclang caching mechanism in build workflow --- .github/workflows/build.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0127558..92ce4d2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,15 +55,15 @@ jobs: python-version: "3.13" cache-dependency-glob: "**/*.py.lock" - - name: Cache libclang - id: cache-libclang - uses: actions/cache@v4 + - name: Restore cached libclang + id: cache-libclang-restore + uses: actions/cache/restore@v4 with: path: lib/libclang key: libclang-${{ matrix.os.runner }}-${{ matrix.os.arch }}-20.1.0-v2 - name: Download libclang - if: steps.cache-libclang.outputs.cache-hit != 'true' + if: steps.cache-libclang-restore.outputs.cache-hit != 'true' run: | uv run scripts/download.py @@ -133,3 +133,13 @@ jobs: run: | gh release upload ${{ github.event.release.tag_name }} "$ASSET_PATH#${{ matrix.os.friendly_name }}" \ --clobber + + - name: Always Save libclang + id: cache-libclang-save + if: always() && steps.cache-libclang-restore.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + key: ${{ steps.cache-libclang-restore.outputs.cache-primary-key }} + path: | + lib/libclang + From 640343ae050a539f10ee65ce61f2912254d8383a Mon Sep 17 00:00:00 2001 From: Zxilly Date: Mon, 20 Oct 2025 00:48:38 +0800 Subject: [PATCH 8/9] fix: remove unnecessary link options for target configurations --- cjpm.toml | 3 --- scripts/cjpm.py | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/cjpm.toml b/cjpm.toml index 92cdb81..2d619bb 100644 --- a/cjpm.toml +++ b/cjpm.toml @@ -22,16 +22,13 @@ [target.x86_64-w64-mingw32.release] compile-option = "-O2" - link-option = "-l:libcangjie-std-ast.dll" [target.aarch64-apple-darwin.release] compile-option = "-O2" [target.x86_64-unknown-linux-gnu.release] compile-option = "-O2" - link-option = "-l:libcangjie-std-ast.so" [target.aarch64-unknown-linux-gnu.release] compile-option = "-O2" - link-option = "-l:libcangjie-std-ast.so" \ No newline at end of file diff --git a/scripts/cjpm.py b/scripts/cjpm.py index cbfd56f..9a64225 100644 --- a/scripts/cjpm.py +++ b/scripts/cjpm.py @@ -102,11 +102,11 @@ def preprocess_environment(env): match sys.platform: case "win32": - ldflags += " -l:libstdc++.a -l:libwinpthread.a -lmingwex -lmsvcrt -lversion " + ldflags += " -l:libstdc++.a -l:libwinpthread.a -lmingwex -lmsvcrt -lversion -l:libcangjie-std-ast.dll " case "darwin": ldflags += " -lc++ -lc++abi -lSystem " case "linux": - ldflags += " -l:libstdc++.a -lgcc_s " + ldflags += " -l:libstdc++.a -lgcc_s -l:libcangjie-std-ast.so " if sys.platform != "darwin": ldflags += "--end-group" From 6b3c5f3075331e03948be919eb98f832d5459f54 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Mon, 20 Oct 2025 00:58:23 +0800 Subject: [PATCH 9/9] fix: float64 toTokens --- scripts/cjpm.py | 4 ++-- src/codegen/workaround.cj | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/scripts/cjpm.py b/scripts/cjpm.py index 9a64225..cbfd56f 100644 --- a/scripts/cjpm.py +++ b/scripts/cjpm.py @@ -102,11 +102,11 @@ def preprocess_environment(env): match sys.platform: case "win32": - ldflags += " -l:libstdc++.a -l:libwinpthread.a -lmingwex -lmsvcrt -lversion -l:libcangjie-std-ast.dll " + ldflags += " -l:libstdc++.a -l:libwinpthread.a -lmingwex -lmsvcrt -lversion " case "darwin": ldflags += " -lc++ -lc++abi -lSystem " case "linux": - ldflags += " -l:libstdc++.a -lgcc_s -l:libcangjie-std-ast.so " + ldflags += " -l:libstdc++.a -lgcc_s " if sys.platform != "darwin": ldflags += "--end-group" diff --git a/src/codegen/workaround.cj b/src/codegen/workaround.cj index 5daf578..13dc1ef 100644 --- a/src/codegen/workaround.cj +++ b/src/codegen/workaround.cj @@ -1,22 +1,21 @@ package cjbind.codegen -import std.ast.{Tokens, Token, TokenKind} +import std.ast.{Tokens, Token, TokenKind, ToTokens, TokenKind} foreign func CJ_AST_Float64ToCPointer(num: Float64): CString // workaround 仓颉标准库中有 bug 的 Float64 to Tokens 转换函数 public func float64toTokens(val: Float64): Tokens { - let strPtr = unsafe { CJ_AST_Float64ToCPointer(val) } - var floatStr = String() - if (!strPtr.isNull()) { - floatStr = strPtr.toString() - unsafe { LibC.free(strPtr) } - } - floatStr = floatStr.replace("+", "") + let oldTokens = val.toTokens() + let tokens = Tokens() - if (val < 0.0) { - return Tokens().append(Token(TokenKind.SUB)).append(Token(TokenKind.FLOAT_LITERAL, floatStr[1..])) + for (token in oldTokens) { + var t = token + if (token.kind == TokenKind.FLOAT_LITERAL && token.value.contains("+")) { + t = Token(TokenKind.FLOAT_LITERAL, token.value.replace("+", "")) + } + tokens.append(t) } - let tok: Token = Token(TokenKind.FLOAT_LITERAL, floatStr) - return tok.toTokens() + + return tokens } \ No newline at end of file