@@ -1386,155 +1386,7 @@ func getListOfPackages(pkgs []string, options *compileopts.Options) ([]string, e
13861386 return pkgNames , nil
13871387}
13881388
1389- func printAutocompleteHelp () {
1390- type pluginHelp struct {
1391- Path string `json:"path,omitempty"`
1392- Short string `json:"short,omitempty"`
1393- Long string `json:"long,omitempty"`
1394- Example string `json:"example,omitempty"`
1395- Args []string `json:"args,omitempty"`
1396- }
1397- buildHelp := pluginHelp {
1398- Path : "transform_build_tinygo" ,
1399- Short : "compile a tinygo module in the current directory" ,
1400- }
1401- b , err := json .Marshal (& []pluginHelp {buildHelp })
1402- if err != nil {
1403- }
1404- fmt .Fprintln (os .Stdout , string (b ))
1405- }
1406-
1407- // This is a pure addition to upstream tinygo.
1408- //
1409- // It provides a hardcoded `build` command and autocomplete support for rpk
14101389func main () {
1411- if len (os .Args ) > 1 {
1412- // Early command processing, before commands are interpreted by the Go flag
1413- // library.
1414- switch os .Args [1 ] {
1415- case "clang" , "ld.lld" , "wasm-ld" :
1416- err := builder .RunTool (os .Args [1 ], os .Args [2 :]... )
1417- if err != nil {
1418- fmt .Fprintln (os .Stderr , err )
1419- os .Exit (1 )
1420- }
1421- os .Exit (0 )
1422- }
1423- }
1424-
1425- command := "build"
1426-
1427- opt := flag .String ("opt" , "z" , "optimization level: 0, 1, 2, s, z" )
1428- gc := flag .String ("gc" , "conservative" , "garbage collector to use (none, leaking, conservative)" )
1429- panicStrategy := flag .String ("panic" , "print" , "panic strategy (print, trap)" )
1430- scheduler := flag .String ("scheduler" , "none" , "which scheduler to use (none, tasks, asyncify)" )
1431- work := flag .Bool ("work" , false , "print the name of the temporary build directory and do not delete this directory on exit" )
1432- interpTimeout := flag .Duration ("interp-timeout" , 180 * time .Second , "interp optimization pass timeout" )
1433- var tags buildutil.TagsFlag
1434- flag .Var (& tags , "tags" , "a space-separated list of extra build tags" )
1435- target := flag .String ("target" , "wasi" , "chip/board name or JSON target specification file" )
1436- var stackSize uint64
1437- flag .Func ("stack-size" , "goroutine stack size (if unknown at compile time)" , func (s string ) error {
1438- size , err := bytesize .Parse (s )
1439- stackSize = uint64 (size )
1440- return err
1441- })
1442- printSize := flag .String ("size" , "" , "print sizes (none, short, full)" )
1443- printStacks := flag .Bool ("print-stacks" , false , "print stack sizes of goroutines" )
1444- printAllocsString := flag .String ("print-allocs" , "" , "regular expression of functions for which heap allocations should be printed" )
1445- printCommands := flag .Bool ("x" , false , "Print commands" )
1446- parallelism := flag .Int ("p" , runtime .GOMAXPROCS (0 ), "the number of build jobs that can run in parallel" )
1447- nodebug := flag .Bool ("no-debug" , false , "strip debug information" )
1448- programmer := flag .String ("programmer" , "" , "which hardware programmer to use" )
1449- ldflags := flag .String ("ldflags" , "" , "Go link tool compatible ldflags" )
1450- llvmFeatures := flag .String ("llvm-features" , "" , "comma separated LLVM features to enable" )
1451- flagJSON := flag .Bool ("json" , false , "print data in JSON format" )
1452- outpath := flag .String ("o" , "" , "output filename" )
1453- helpAutocomplete := flag .Bool ("help-autocomplete" , false , "output complete help for rpk" )
1454- // strip the .rpk.managed-tinygo prefix
1455- flag .CommandLine .Parse (os .Args [1 :])
1456-
1457- if * helpAutocomplete {
1458- printAutocompleteHelp ()
1459- os .Exit (0 )
1460- }
1461-
1462- globalVarValues , err := parseGoLinkFlag (* ldflags )
1463- if err != nil {
1464- fmt .Fprintln (os .Stderr , err )
1465- os .Exit (1 )
1466- }
1467-
1468- var printAllocs * regexp.Regexp
1469- if * printAllocsString != "" {
1470- printAllocs , err = regexp .Compile (* printAllocsString )
1471- if err != nil {
1472- fmt .Fprintln (os .Stderr , err )
1473- os .Exit (1 )
1474- }
1475- }
1476- options := & compileopts.Options {
1477- GOOS : goenv .Get ("GOOS" ),
1478- GOARCH : goenv .Get ("GOARCH" ),
1479- GOARM : goenv .Get ("GOARM" ),
1480- Target : * target ,
1481- StackSize : stackSize ,
1482- Opt : * opt ,
1483- GC : * gc ,
1484- PanicStrategy : * panicStrategy ,
1485- Scheduler : * scheduler ,
1486- Serial : "" ,
1487- Work : * work ,
1488- InterpTimeout : * interpTimeout ,
1489- PrintIR : false ,
1490- DumpSSA : false ,
1491- VerifyIR : false ,
1492- SkipDWARF : false ,
1493- Semaphore : make (chan struct {}, * parallelism ),
1494- Debug : ! * nodebug ,
1495- PrintSizes : * printSize ,
1496- PrintStacks : * printStacks ,
1497- PrintAllocs : printAllocs ,
1498- Tags : []string (tags ),
1499- TestConfig : compileopts.TestConfig {},
1500- GlobalValues : globalVarValues ,
1501- Programmer : * programmer ,
1502- OpenOCDCommands : nil ,
1503- LLVMFeatures : * llvmFeatures ,
1504- PrintJSON : * flagJSON ,
1505- Monitor : false ,
1506- BaudRate : 115200 ,
1507- Timeout : 20 * time .Second ,
1508- }
1509- if * printCommands {
1510- options .PrintCommands = printCommand
1511- }
1512- err = options .Verify ()
1513- if err != nil {
1514- fmt .Fprintln (os .Stderr , err .Error ())
1515- usage (command )
1516- os .Exit (1 )
1517- }
1518- pkgName := "."
1519- if flag .NArg () == 1 {
1520- pkgName = filepath .ToSlash (flag .Arg (0 ))
1521- } else if flag .NArg () > 1 {
1522- fmt .Fprintln (os .Stderr , "build only accepts a single positional argument: package name, but multiple were specified" )
1523- usage (command )
1524- os .Exit (1 )
1525- }
1526- if options .Target == "" && filepath .Ext (* outpath ) == ".wasm" {
1527- options .Target = "wasm"
1528- }
1529-
1530- err = Build (pkgName , * outpath , options )
1531- handleCompilerError (err )
1532- fmt .Println ("build successful" )
1533- fmt .Println ("deploy your transform to a topic:" )
1534- fmt .Println ("\t rpk transform deploy" )
1535- }
1536-
1537- func upstreamMain () {
15381390 if len (os .Args ) < 2 {
15391391 fmt .Fprintln (os .Stderr , "No command-line arguments supplied." )
15401392 usage ("" )
0 commit comments