GitHubНачать

Справочник API собран из Go doc-комментариев в исходном коде и написан на английском языке.

package sizecheck

import "github.com/nsgo-dev/game/pkg/tooling/sizecheck"

Обзор

Package sizecheck measures a built package (a WebAssembly binary, an Android AAB or APK, or an iOS IPA) and checks it against a size budget, the checks behind `game size`. It also finds and measures the packages `nsgo build` writes under an output directory, which the editor's Build and Release screen reports.

Указатель

Константы

const (
	// Shared categories.
	CategoryResources = "resources"
	CategoryOther     = "other"

	// Android categories (AAB and APK).
	CategoryNativeLibs   = "native_libs"
	CategoryDEX          = "dex"
	CategoryAssets       = "assets"
	CategoryManifestMeta = "manifest_meta"

	// iOS categories (IPA).
	CategoryExecutable    = "executable"
	CategoryFrameworks    = "frameworks"
	CategoryAssetsCar     = "assets_car"
	CategoryLproj         = "lproj"
	CategoryCodeSignature = "code_signature"
)

Content category keys for Android AAB/APK and iOS IPA packages.

const DefaultTopLargestFiles = 10

DefaultTopLargestFiles is the default number of largest archive entries kept in MobilePackageReport.LargestFiles.

Функции

func FormatBudgetReport(rep BudgetReport) string

FormatBudgetReport renders a human-readable summary of rep.

func FormatMobileReport(rep MobilePackageReport) string

FormatMobileReport renders a GitHub-flavored Markdown summary suitable for terminal output and $GITHUB_STEP_SUMMARY.

func FormatWasmMarkdownReport(rep BudgetReport) string

FormatWasmMarkdownReport renders a Markdown summary for a WebAssembly BudgetReport.

func PackageDir(outDir, appName, appVersion, target string) string

PackageDir returns NSGo's per-target package directory under outDir: `<outDir>/<appName>-<appVersion>-<target>` (matching cmd/nsgo/build.go).

func PackageSlug(appName, appID string) string

PackageSlug returns NSGo's package file slug for an app (matching NSGo's cmd/nsgo/installer.go packageSlug): lowercase ASCII words from appName joined by hyphens, else the last dot-separated segment of appID, else "app".

func ReleaseName(appName, appID, appVersion, target, suffix string) string

ReleaseName returns NSGo's release file name for target and suffix: `<slug>-<version>-<target-with-hyphens><suffix>` (matching cmd/nsgo/installer.go).

Типы

type ArtifactMeasurement struct {
	Found           bool                 `json:"found"`
	ArtifactPath    string               `json:"artifact_path,omitempty"`
	ArtifactName    string               `json:"artifact_name,omitempty"`
	Kind            PackageKind          `json:"kind,omitempty"`
	SizeBytes       int64                `json:"size_bytes"`
	WasmMeasurement *Measurement         `json:"wasm_measurement,omitempty"`
	MobileReport    *MobilePackageReport `json:"mobile_report,omitempty"`
	Categories      CategoryTotals       `json:"categories"`
	WebBuildDir     string               `json:"web_build_dir,omitempty"`
}

ArtifactMeasurement is the result of finding and measuring a real package written by `nsgo build` under a release output directory. When no package exists for the requested platform, Found is false and all byte counts are zero.

func MeasureBuiltArtifact(outDir, appName, appID, appVersion, platform string, targets []string) (ArtifactMeasurement, error)

MeasureBuiltArtifact locates the package `nsgo build` wrote under outDir for platform (and its concrete targets) and measures its real bytes and categories. If no built artifact exists in outDir, it returns ArtifactMeasurement{Found: false}, nil.

type BudgetExceededError struct {
	Report MobilePackageReport
}

BudgetExceededError is returned by CheckMobilePackage when one or more limits in MobileBudget are exceeded. Its Error text includes all violations and the full Markdown space breakdown.

func (e *BudgetExceededError) Error() string

Error lists every budget violation followed by the Markdown space breakdown of the package.

type BudgetFile struct {
	Target       string `json:"target"`
	LDFlags      string `json:"ldflags"`
	MaxRawBytes  int64  `json:"max_raw_bytes"`
	MaxGzipBytes int64  `json:"max_gzip_bytes"`
	Note         string `json:"note,omitempty"`
}

BudgetFile is the JSON schema stored in benchmarks/web-budget.json.

func LoadBudget(path string) (BudgetFile, error)

LoadBudget reads and decodes a BudgetFile from path. Its errors are *loaderr.Error values that name path, with the line of the problem and how to fix it.

type BudgetReport struct {
	Budget     BudgetFile  `json:"budget"`
	Measured   Measurement `json:"measured"`
	Violations []string    `json:"violations,omitempty"`
}

BudgetReport holds the result of comparing a Measurement against a BudgetFile.

func EvaluateBudget(budget BudgetFile, got Measurement) BudgetReport

EvaluateBudget checks got against budget and returns a BudgetReport.

func (r BudgetReport) Passed() bool

Passed reports whether both raw and gzipped sizes are within budget.

type CategoryTotals struct {
	CodeBytes     int64 `json:"code_bytes"`
	TexturesBytes int64 `json:"textures_bytes"`
	AudioBytes    int64 `json:"audio_bytes"`
	OtherBytes    int64 `json:"other_bytes"`
}

CategoryTotals aggregates real measured package bytes into four top-level buckets displayed by the editor's Build and Release screen and release reports.

func (c CategoryTotals) Total() int64

Total returns the sum of all four category totals.

type FileEntry struct {
	Path              string `json:"path"`
	Category          string `json:"category"`
	ABI               string `json:"abi,omitempty"`
	CompressedBytes   int64  `json:"compressed_bytes"`
	UncompressedBytes int64  `json:"uncompressed_bytes"`
}

FileEntry describes one file inside a mobile package archive.

type Measurement struct {
	RawBytes  int64 `json:"raw_bytes"`
	GzipBytes int64 `json:"gzip_bytes"`
}

Measurement stores measured raw and gzip-compressed WebAssembly sizes.

func MeasureWasm(wasm []byte) (Measurement, error)

MeasureWasm returns the raw and gzipped (BestCompression) byte sizes of wasm.

type MobileBudget struct {
	// MaxTotalBytes limits the total package archive size on disk.
	MaxTotalBytes int64 `json:"max_total_bytes"`
	// MaxPerABIBytes limits the compressed native library bytes for any single
	// Android ABI (e.g. arm64-v8a, armeabi-v7a, x86_64).
	MaxPerABIBytes int64 `json:"max_per_abi_bytes,omitempty"`
	// MaxCategoryBytes limits compressed bytes per category key
	// (e.g. "native_libs", "dex", "executable", "frameworks").
	MaxCategoryBytes map[string]int64 `json:"max_category_bytes,omitempty"`
	// Note documents the rationale behind the budget thresholds.
	Note string `json:"note,omitempty"`
}

MobileBudget defines size budgets (in bytes) for Android AAB/APK and iOS IPA packages. Any limit <= 0 is treated as unbounded.

func DefaultAndroidAABBudget() MobileBudget

DefaultAndroidAABBudget returns the documented default size budget for an Android App Bundle (.aab).

Google Play caps per-device base-module downloads at 200 MiB. Keeping the combined AAB within 50 MiB total and 20 MiB per native ABI leaves headroom for game assets while preserving fast mobile install conversion.

func DefaultAndroidAPKBudget() MobileBudget

DefaultAndroidAPKBudget returns the documented default size budget for an Android APK (.apk).

Multi-ABI APKs ship native libraries for every targeted ABI directly in the installable file. Keeping APKs within 40 MiB total and 20 MiB per ABI keeps direct downloads lean (well below the 100 MiB legacy APK ceiling).

func DefaultIOSIPABudget() MobileBudget

DefaultIOSIPABudget returns the documented default size budget for an iOS App Store Package (.ipa).

Apple enforces a 200 MiB cellular download threshold. Keeping IPAs within 50 MiB total ensures fast cellular downloads even before App Thinning.

func DefaultMobileBudget(kind PackageKind) (MobileBudget, error)

DefaultMobileBudget returns the default MobileBudget for kind.

func LoadMobileBudget(filePath string) (MobileBudget, error)

LoadMobileBudget reads and decodes a MobileBudget JSON file from filePath. Its errors are *loaderr.Error values that name filePath, with the line of the problem and how to fix it.

type MobilePackageReport struct {
	Path              string                   `json:"path"`
	Kind              PackageKind              `json:"kind"`
	ArchiveBytes      int64                    `json:"archive_bytes"`
	CompressedBytes   int64                    `json:"compressed_bytes"`
	UncompressedBytes int64                    `json:"uncompressed_bytes"`
	FileCount         int                      `json:"file_count"`
	Categories        map[string]SizeBreakdown `json:"categories"`
	ABIs              map[string]SizeBreakdown `json:"abis,omitempty"`
	LargestFiles      []FileEntry              `json:"largest_files"`
	Budget            MobileBudget             `json:"budget"`
	Violations        []string                 `json:"violations,omitempty"`
	Passed            bool                     `json:"passed"`
}

MobilePackageReport holds the full size breakdown and budget evaluation for an Android AAB/APK or iOS IPA archive.

func CheckMobilePackage(pkgPath string, kind PackageKind, budget MobileBudget) (MobilePackageReport, error)

CheckMobilePackage inspects pkgPath as kind and enforces budget.

When the archive is readable, CheckMobilePackage always returns the populated MobilePackageReport. If any budget limit is exceeded, it also returns a *BudgetExceededError whose message contains every violation and the full Markdown space breakdown.

func EvaluateMobileBudget(rep MobilePackageReport, budget MobileBudget) MobilePackageReport

EvaluateMobileBudget evaluates an inspected MobilePackageReport against budget, populating Budget, Violations, and Passed.

func InspectMobilePackage(pkgPath string, kind PackageKind) (MobilePackageReport, error)

InspectMobilePackage opens the ZIP-based mobile archive at pkgPath and computes its category, ABI, and largest-file breakdowns.

func InspectMobileReader(r io.ReaderAt, archiveSize int64, displayPath string, kind PackageKind) (MobilePackageReport, error)

InspectMobileReader inspects a ZIP-based mobile package from r with total archive byte length archiveSize.

type PackageKind string

PackageKind identifies the package artifact format inspected by sizecheck.

const (
	PackageKindWasm PackageKind = "wasm"
	PackageKindAAB  PackageKind = "aab"
	PackageKindAPK  PackageKind = "apk"
	PackageKindIPA  PackageKind = "ipa"
)
func DetectPackageKind(filePath string) (PackageKind, bool)

DetectPackageKind infers a PackageKind from filePath's extension.

func ParsePackageKind(raw string) (PackageKind, error)

ParsePackageKind parses a CLI -kind value into a PackageKind.

type SizeBreakdown struct {
	CompressedBytes   int64 `json:"compressed_bytes"`
	UncompressedBytes int64 `json:"uncompressed_bytes"`
	FileCount         int   `json:"file_count"`
}

SizeBreakdown holds compressed and uncompressed byte totals plus entry count for a single category or ABI bucket.