feat: add size level aggregation

This commit is contained in:
Li Jie
2025-11-17 14:09:27 +08:00
parent b25ae1b4e7
commit cee22db053
6 changed files with 902 additions and 0 deletions

View File

@@ -132,6 +132,9 @@ type Config struct {
CheckLinkArgs bool // check linkargs valid
ForceEspClang bool // force to use esp-clang
Tags string
SizeReport bool // print size report after successful build
SizeFormat string // size report format: text,json
SizeLevel string // size aggregation level: full,module,package
// GlobalRewrites specifies compile-time overrides for global string variables.
// Keys are fully qualified package paths (e.g. "main" or "github.com/user/pkg").
// Each Rewrites entry maps variable names to replacement string values. Only
@@ -205,6 +208,15 @@ func Do(args []string, conf *Config) ([]Package, error) {
if conf.BuildMode == "" {
conf.BuildMode = BuildModeExe
}
if conf.SizeReport && conf.SizeFormat == "" {
conf.SizeFormat = "text"
}
if conf.SizeReport && conf.SizeLevel == "" {
conf.SizeLevel = "module"
}
if err := ensureSizeReporting(conf); err != nil {
return nil, err
}
// Handle crosscompile configuration first to set correct GOOS/GOARCH
forceEspClang := conf.ForceEspClang || conf.Target != ""
export, err := crosscompile.Use(conf.Goos, conf.Goarch, conf.Target, IsWasiThreadsEnabled(), forceEspClang)
@@ -380,6 +392,11 @@ func Do(args []string, conf *Config) ([]Package, error) {
if err != nil {
return nil, err
}
if conf.Mode == ModeBuild && conf.SizeReport {
if err := reportBinarySize(outFmts.Out, conf.SizeFormat, conf.SizeLevel, allPkgs); err != nil {
return nil, err
}
}
// Generate C headers for c-archive and c-shared modes before linking
if ctx.buildConf.BuildMode == BuildModeCArchive || ctx.buildConf.BuildMode == BuildModeCShared {