mirror of
				https://github.com/goplus/llgo.git
				synced 2025-10-31 11:17:11 +08:00 
			
		
		
		
	 e05c8b9f46
			
		
	
	e05c8b9f46
	
	
	
		
			
			- Add BuildMode type with three build modes: exe, c-archive, c-shared - Restrict buildmode flag to llgo build command only (not run/install/test) - Implement build mode specific linker arguments: - c-shared: use -shared -fPIC flags - c-archive: use ar tool to create static archive - exe: default executable mode - Add normalizeOutputPath function for platform-specific file naming conventions - Generate C header files for library modes - Fix buildmode flag conflict by removing from PassArgs - Add comprehensive test coverage for all build modes - Resolve duplicate logic between defaultAppExt and normalizeOutputPath 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
		
			
				
	
	
		
			83 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			83 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package base
 | |
| 
 | |
| import (
 | |
| 	"flag"
 | |
| 	"fmt"
 | |
| 	"strings"
 | |
| )
 | |
| 
 | |
| type stringValue struct {
 | |
| 	p    *PassArgs
 | |
| 	name string
 | |
| }
 | |
| 
 | |
| func (p *stringValue) String() string {
 | |
| 	return ""
 | |
| }
 | |
| 
 | |
| func (p *stringValue) Set(v string) error {
 | |
| 	p.p.Args = append(p.p.Args, fmt.Sprintf("-%v=%v", p.name, v))
 | |
| 	return nil
 | |
| }
 | |
| 
 | |
| type boolValue struct {
 | |
| 	p    *PassArgs
 | |
| 	name string
 | |
| }
 | |
| 
 | |
| func (p *boolValue) String() string {
 | |
| 	return ""
 | |
| }
 | |
| 
 | |
| func (p *boolValue) Set(v string) error {
 | |
| 	p.p.Args = append(p.p.Args, fmt.Sprintf("-%v=%v", p.name, v))
 | |
| 	return nil
 | |
| }
 | |
| 
 | |
| func (p *boolValue) IsBoolFlag() bool {
 | |
| 	return true
 | |
| }
 | |
| 
 | |
| type PassArgs struct {
 | |
| 	Args []string
 | |
| 	Flag *flag.FlagSet
 | |
| }
 | |
| 
 | |
| func (p *PassArgs) Tags() string {
 | |
| 	for _, v := range p.Args {
 | |
| 		if strings.HasPrefix(v, "-tags=") {
 | |
| 			return v[6:]
 | |
| 		}
 | |
| 	}
 | |
| 	return ""
 | |
| }
 | |
| 
 | |
| func (p *PassArgs) Var(names ...string) {
 | |
| 	for _, name := range names {
 | |
| 		p.Flag.Var(&stringValue{p: p, name: name}, name, "")
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (p *PassArgs) Bool(names ...string) {
 | |
| 	for _, name := range names {
 | |
| 		p.Flag.Var(&boolValue{p: p, name: name}, name, "")
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func NewPassArgs(flag *flag.FlagSet) *PassArgs {
 | |
| 	p := &PassArgs{Flag: flag}
 | |
| 	return p
 | |
| }
 | |
| 
 | |
| func PassBuildFlags(cmd *Command) *PassArgs {
 | |
| 	p := NewPassArgs(&cmd.Flag)
 | |
| 	p.Bool("n", "x")
 | |
| 	p.Bool("a")
 | |
| 	p.Bool("linkshared", "race", "msan", "asan",
 | |
| 		"trimpath", "work")
 | |
| 	p.Var("p", "asmflags", "compiler",
 | |
| 		"gcflags", "gccgoflags", "installsuffix",
 | |
| 		"ldflags", "pkgdir", "toolexec", "buildvcs")
 | |
| 	return p
 | |
| }
 |