Skip to content

fix: guard native code on portable builds#14

Merged
liuq19 merged 2 commits intocloudwego:mainfrom
liuq19:fix/compile
Apr 29, 2026
Merged

fix: guard native code on portable builds#14
liuq19 merged 2 commits intocloudwego:mainfrom
liuq19:fix/compile

Conversation

@liuq19
Copy link
Copy Markdown
Contributor

@liuq19 liuq19 commented Apr 28, 2026

Summary

  • Run gofmt across the repository in a separate commit.
  • Restrict the x86 native assembly path to amd64 && !noasm && !appengine builds.
  • Add a standard-library fallback for non-amd64, noasm, and appengine builds.
  • Preserve amd64 _subr__b64decode / _subr__b64encode compatibility symbols while avoiding native imports in fallback builds.
  • Upgrade github.com/bytedance/sonic/loader to v0.5.1 for Go 1.26 native runtime compatibility.

Motivation

The native SSE/AVX2 implementation imports the loader/native path and is only valid for x86 native builds. Without explicit architecture constraints, portable builds such as darwin/arm64 with Go 1.20 can select the native path and fail before package-level fallback behavior is available.

Go 1.26 also changes the native loader runtime/moduledata behavior. With sonic/loader v0.3.0, darwin/amd64 native tests fail at init time with fatal error: invalid function symbol table from runtime.moduledataverify1. sonic/loader v0.5.1 includes the upstream Go 1.26 loader support.

Implementation Notes

  • Native encode / decode are compiled only for amd64 && !noasm && !appengine.
  • Fallback encode / decode use encoding/base64 for portable builds.
  • JSON string-body unquoting in the fallback path uses encoding/json for simpler, standard behavior.
  • Fallback decode returns encoding/base64 errors directly instead of rewriting missing-padding error positions.

Validation

  • GOTOOLCHAIN=go1.26.0 GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go test -run 'TestEncoder|TestDecoder|TestSubrCompatibilitySymbols' -count=1 -v .
  • GOTOOLCHAIN=go1.26.0 GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go test -run '^$' -exec=/usr/bin/true .
  • GOTOOLCHAIN=go1.26.0 CGO_ENABLED=0 go test -tags noasm -run '^$' .
  • GOTOOLCHAIN=go1.20.14 CGO_ENABLED=0 go test .
  • GOTOOLCHAIN=go1.20.14 CGO_ENABLED=0 go test -tags noasm .
  • GOTOOLCHAIN=go1.20.14 CGO_ENABLED=0 go test -tags appengine .
  • GOTOOLCHAIN=go1.20.14 CGO_ENABLED=0 go test ./...
  • GOTOOLCHAIN=go1.20.14 GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go test -run '^$' .
  • GOTOOLCHAIN=go1.20.14 GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go test -run '^$' -exec=/usr/bin/true .
  • GOTOOLCHAIN=go1.20.14 GOOS=linux GOARCH=riscv64 CGO_ENABLED=0 go test -run '^$' -exec=/usr/bin/true .
  • GOTOOLCHAIN=go1.17.13 CGO_ENABLED=0 go test .
  • GitHub Actions: staticcheck, compliant, Go 1.17-1.23 tests, and fallback matrix all pass.

@liuq19 liuq19 marked this pull request as ready for review April 28, 2026 06:28
Copilot AI review requested due to automatic review settings April 28, 2026 06:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes cross-architecture build selection for the project’s native (SSE/AVX2) implementation by adding explicit amd64 build constraints and introducing a standard-library fallback for non-amd64, noasm, and appengine builds.

Changes:

  • Added //go:build amd64 && !noasm && !appengine constraints across native dispatch/export/generated code so non-amd64 builds can’t select the x86 loader path.
  • Introduced split implementations in base64x: a native-backed version for amd64 and a stdlib-based fallback for other build contexts.
  • Updated CI workflows and typo configuration; ran gofmt-style formatting updates across multiple files.

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
internal/rt/fastmem.go gofmt/comment formatting adjustments in low-level runtime helpers.
internal/rt/asm_arm64.s Added license header above existing build constraints for ARM64 asm.
internal/rt/asm_amd64.s Added license header above existing build constraints for AMD64 asm.
internal/native/sse/native_export.go Added amd64 && !noasm && !appengine build constraints; gofmt import/indent cleanup.
internal/native/sse/b64encode_text_amd64.go Tightened build constraints and gofmt formatting of generated text blob.
internal/native/sse/b64encode_subr.go Tightened build constraints and gofmt formatting.
internal/native/sse/b64encode.go Tightened build constraints and gofmt formatting.
internal/native/sse/b64decode_text_amd64.go Tightened build constraints and gofmt formatting of generated text blob.
internal/native/sse/b64decode_subr.go Tightened build constraints and gofmt formatting.
internal/native/sse/b64decode.go Tightened build constraints and gofmt formatting.
internal/native/avx2/native_export.go Added amd64 && !noasm && !appengine build constraints; gofmt import/indent cleanup.
internal/native/avx2/b64encode_text_amd64.go Tightened build constraints and gofmt formatting of generated text blob.
internal/native/avx2/b64encode_subr.go Tightened build constraints and gofmt formatting.
internal/native/avx2/b64encode.go Tightened build constraints and gofmt formatting.
internal/native/avx2/b64decode_text_amd64.go Tightened build constraints and gofmt formatting of generated text blob.
internal/native/avx2/b64decode_subr.go Tightened build constraints and gofmt formatting.
internal/native/avx2/b64decode.go Tightened build constraints and gofmt formatting.
internal/native/native_test.go Restricted native tests to amd64 && !noasm && !appengine; gofmt formatting.
internal/native/native_export.tmpl Added amd64 && !noasm && !appengine build constraints to template output.
internal/native/dispatch.go Added license header + amd64 && !noasm && !appengine build constraints; import order/gofmt cleanup.
internal/native/b64encode.tmpl Added amd64 && !noasm && !appengine build constraints to template output.
internal/native/b64decode.tmpl Added amd64 && !noasm && !appengine build constraints to template output.
fuzz_test.go Added //go:build go1.18; gofmt import/loop formatting.
faststr.go gofmt formatting and comment spacing.
bench/bench_test.go Added license header; gofmt formatting and import ordering.
base64x_test.go gofmt formatting across tests.
base64x_subr_amd64.go Added license header + tighter build constraints for native subr symbols.
base64x_native.go New file: native-backed encode/decode helpers under amd64 && !noasm && !appengine.
base64x_fallback.go New file: stdlib-based fallback encode/decode under `!amd64
base64x.go Removed direct native import; routed through build-tagged encode/decode helpers; gofmt cleanup.
_typos.toml Excluded base64x_test.go from typos; added shll extended word.
.github/workflows/tests.yml Updated actions versions; added fallback build/compile matrix job.
.github/workflows/pr-check.yml Moved to hosted runner; updated action versions; minor YAML cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread base64x_fallback.go Outdated
Comment thread _typos.toml Outdated
Comment thread base64x_native.go Outdated
Comment thread .github/workflows/tests.yml Outdated
Comment thread base64x_subr_amd64.go Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de877db460

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread base64x_subr_amd64.go Outdated
@liuq19 liuq19 force-pushed the fix/compile branch 6 times, most recently from 2cddb16 to a3259a4 Compare April 29, 2026 07:09
@liuq19 liuq19 changed the title fix: guard native code on non-amd64 builds fix: guard native code on portable builds Apr 29, 2026
Split native amd64 code from the stdlib fallback path, preserve amd64 linkname compatibility symbols for noasm/appengine builds, and cover fallback targets in CI.
@liuq19 liuq19 merged commit 33496ef into cloudwego:main Apr 29, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants