Skip to content

feat: support libc/compiler-rt for small places#1246

Merged
xushiwei merged 24 commits intogoplus:mainfrom
MeteorsLiu:esp-libc
Sep 2, 2025
Merged

feat: support libc/compiler-rt for small places#1246
xushiwei merged 24 commits intogoplus:mainfrom
MeteorsLiu:esp-libc

Conversation

@MeteorsLiu
Copy link
Contributor

@MeteorsLiu MeteorsLiu commented Aug 28, 2025

Resolves #1248 (Design)

Current support: ESP32

@MeteorsLiu MeteorsLiu changed the title [WIP]feat: support libc [WIP]feat: support libc for small places Aug 28, 2025
@MeteorsLiu MeteorsLiu changed the title [WIP]feat: support libc for small places [WIP]feat: support libc/compiler-rt for small places Aug 29, 2025
Copy link
Member

Choose a reason for hiding this comment

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

where is this link script come from

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

where is this .ld come from

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MeteorsLiu MeteorsLiu force-pushed the esp-libc branch 7 times, most recently from d7fe65e to f860698 Compare September 1, 2025 14:13
@codecov
Copy link

codecov bot commented Sep 2, 2025

Codecov Report

❌ Patch coverage is 93.24117% with 44 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.28%. Comparing base (ddc61ad) to head (977806a).
⚠️ Report is 61 commits behind head on main.

Files with missing lines Patch % Lines
internal/crosscompile/fetch.go 70.66% 15 Missing and 7 partials ⚠️
internal/crosscompile/crosscompile.go 71.64% 12 Missing and 7 partials ⚠️
internal/crosscompile/compile/compile.go 94.64% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1246      +/-   ##
==========================================
+ Coverage   87.79%   90.28%   +2.49%     
==========================================
  Files          35       40       +5     
  Lines        8928    11704    +2776     
==========================================
+ Hits         7838    10567    +2729     
- Misses        979     1010      +31     
- Partials      111      127      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

fix: libc include dir

fix: xtensa internal src dir

fix: xtensa internal src dir

fix: ignore wasm target

fix: export libc cflags to global cflags

fix: rtlib libc include dir

fix: ignore some errors for libc

fix: don's search system path for libc

fix: adjust compiling options

ci: add libc

fix: libc cflags

fix: test path

fix: libc cflags

fix: libc cflags
test: add asm test

test: add libc.go test

test: add DownloadAndExtractLibInternalDir test

test: fix checkDownload test

test: fix asm test

fix: check isCompile

fix: remove debug

fix: remove debug
Comment on lines -5 to +10
"build-tags": ["xtensa", "baremetal", "linux", "arm"],
"build-tags": [
"xtensa",
"baremetal",
"linux",
"arm"
],
Copy link
Member

Choose a reason for hiding this comment

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

unexpect unuse style change

// If targetName is provided, it takes precedence over goos/goarch
func Use(goos, goarch string, wasiThreads bool, targetName string) (export Export, err error) {
if targetName != "" {
if targetName != "" && !strings.HasPrefix(targetName, "wasm") && !strings.HasPrefix(targetName, "wasi") {
Copy link
Member

Choose a reason for hiding this comment

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

Is it because wasm currently doesn't support the --target approach? Also, llgo will indeed have another way to support wasm now. I think we should still leave a comment here to indicate this situation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Crosscompile has been implemented wasm/wasi, those target names are migrated from tinygo, should not useTarget.

Comment on lines +259 to +282
CFlags: []string{
"-DNDEBUG",
"-DVISIBILITY_HIDDEN",
},
CCFlags: []string{
"-Oz",
"-fno-ident",
"-Wno-unused-parameter",
"-fno-lto",
"-Werror=array-bounds",
"-Werror=uninitialized",
"-Werror=shadow",
"-Werror=empty-body",
"-Werror=sizeof-pointer-memaccess",
"-Werror=sizeof-array-argument",
"-Werror=suspicious-memaccess",
"-Werror=builtin-memcpy-chk-size",
"-Werror=array-bounds-pointer-arithmetic",
"-Werror=return-stack-address",
"-Werror=sizeof-array-decay",
"-Werror=format-insufficient-args",
"-Wformat -std=c11",
"-fno-builtin",
"-fvisibility=hidden",
Copy link
Member

Choose a reason for hiding this comment

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

where is these flags come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +111 to +126
filepath.Join(baseDir, "lib", "builtins", "absvdi2.c"),
filepath.Join(baseDir, "lib", "builtins", "absvsi2.c"),
filepath.Join(baseDir, "lib", "builtins", "absvti2.c"),
filepath.Join(baseDir, "lib", "builtins", "adddf3.c"),
filepath.Join(baseDir, "lib", "builtins", "addsf3.c"),
filepath.Join(baseDir, "lib", "builtins", "addvdi3.c"),
filepath.Join(baseDir, "lib", "builtins", "addvsi3.c"),
filepath.Join(baseDir, "lib", "builtins", "addvti3.c"),
filepath.Join(baseDir, "lib", "builtins", "apple_versioning.c"),
filepath.Join(baseDir, "lib", "builtins", "ashldi3.c"),
filepath.Join(baseDir, "lib", "builtins", "ashlti3.c"),
filepath.Join(baseDir, "lib", "builtins", "ashrdi3.c"),
filepath.Join(baseDir, "lib", "builtins", "ashrti3.c"),
filepath.Join(baseDir, "lib", "builtins", "bswapdi2.c"),
filepath.Join(baseDir, "lib", "builtins", "bswapsi2.c"),
filepath.Join(baseDir, "lib", "builtins", "clzdi2.c"),
Copy link
Member

Choose a reason for hiding this comment

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

Where does this C language file list come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MeteorsLiu MeteorsLiu marked this pull request as ready for review September 2, 2025 11:08
@MeteorsLiu MeteorsLiu changed the title [WIP]feat: support libc/compiler-rt for small places feat: support libc/compiler-rt for small places Sep 2, 2025
filepath.Join(baseDir, "lib", "builtins", "subtf3.c"),
filepath.Join(baseDir, "lib", "builtins", "trunctfdf2.c"),
filepath.Join(baseDir, "lib", "builtins", "trunctfhf2.c"),
filepath.Join(baseDir, "lib", "builtins", "trunctfsf2.c"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Split multiline string is better for codegen and tests

@xushiwei xushiwei merged commit 6588f36 into goplus:main Sep 2, 2025
34 checks passed
Comment on lines +1 to +16
package main

import "github.com/goplus/lib/c"

func myprint(s *c.Char) {
for i := 0; i < int(c.Strlen(s)); i++ {
WriteByte(byte(c.Index(s, i)))
}
}

func main() {
for {
myprint(c.Str("hello world"))
sleep(1)
}
}
Copy link
Member

@luoliwoshang luoliwoshang Sep 3, 2025

Choose a reason for hiding this comment

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

#1257 the issue for how to run this demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support libc / compiler-rt for embedded device

4 participants