feat: implement target configuration system for issue #1176
Add comprehensive target configuration parsing and inheritance system: - Create internal/targets package with config structures - Support JSON configuration loading with inheritance resolution - Implement multi-level inheritance (e.g., rp2040 → cortex-m0plus → cortex-m) - Add 206 target configurations from TinyGo for embedded platforms - Support core fields: name, llvm-target, cpu, features, build-tags, goos, goarch, cflags, ldflags - Provide high-level resolver interface for target lookup - Include comprehensive unit tests with 100% target parsing coverage This foundation enables future -target parameter support for cross-compilation to diverse embedded platforms beyond current GOOS/GOARCH limitations. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
73
internal/targets/example_test.go
Normal file
73
internal/targets/example_test.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package targets_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sort"
|
||||
|
||||
"github.com/goplus/llgo/internal/targets"
|
||||
)
|
||||
|
||||
func ExampleResolver_Resolve() {
|
||||
resolver := targets.NewDefaultResolver()
|
||||
|
||||
// Resolve a specific target
|
||||
config, err := resolver.Resolve("rp2040")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Printf("Target: %s\n", config.Name)
|
||||
fmt.Printf("LLVM Target: %s\n", config.LLVMTarget)
|
||||
fmt.Printf("CPU: %s\n", config.CPU)
|
||||
fmt.Printf("GOOS: %s\n", config.GOOS)
|
||||
fmt.Printf("GOARCH: %s\n", config.GOARCH)
|
||||
if len(config.BuildTags) > 0 {
|
||||
fmt.Printf("Build Tags: %v\n", config.BuildTags)
|
||||
}
|
||||
if len(config.CFlags) > 0 {
|
||||
fmt.Printf("C Flags: %v\n", config.CFlags)
|
||||
}
|
||||
if len(config.LDFlags) > 0 {
|
||||
fmt.Printf("LD Flags: %v\n", config.LDFlags)
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleResolver_ListAvailableTargets() {
|
||||
resolver := targets.NewDefaultResolver()
|
||||
|
||||
targets, err := resolver.ListAvailableTargets()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Show first 10 targets
|
||||
sort.Strings(targets)
|
||||
fmt.Printf("Available targets (first 10 of %d):\n", len(targets))
|
||||
for i, target := range targets[:10] {
|
||||
fmt.Printf("%d. %s\n", i+1, target)
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleResolver_ResolveAll() {
|
||||
resolver := targets.NewDefaultResolver()
|
||||
|
||||
configs, err := resolver.ResolveAll()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Count targets by GOOS
|
||||
goosCounts := make(map[string]int)
|
||||
for _, config := range configs {
|
||||
if config.GOOS != "" {
|
||||
goosCounts[config.GOOS]++
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Loaded %d target configurations\n", len(configs))
|
||||
fmt.Printf("GOOS distribution:\n")
|
||||
for goos, count := range goosCounts {
|
||||
fmt.Printf(" %s: %d targets\n", goos, count)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user