diff --git a/completers/go-tool-link_completer/cmd/root.go b/completers/go-tool-link_completer/cmd/root.go new file mode 100644 index 0000000000..17cd3a45d4 --- /dev/null +++ b/completers/go-tool-link_completer/cmd/root.go @@ -0,0 +1,101 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/golang" + "github.com/spf13/cobra" +) + +var rootCmd = &cobra.Command{ + Use: "go-tool-link", + Short: "go linker", + Long: "https://pkg.go.dev/cmd/link", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func Execute() error { + return rootCmd.Execute() +} +func init() { + carapace.Gen(rootCmd).Standalone() + + rootCmd.Flags().StringS("B", "B", "", "add an ELF NT_GNU_BUILD_ID note when using ELF") + rootCmd.Flags().StringS("E", "E", "", "set entry symbol name") + rootCmd.Flags().StringS("H", "H", "", "set header type") + rootCmd.Flags().StringS("I", "I", "", "use linker as ELF dynamic linker") + rootCmd.Flags().StringSliceS("L", "L", []string{}, "add specified directory to library path") + rootCmd.Flags().StringS("R", "R", "", "set address rounding quantum (default -1)") + rootCmd.Flags().StringS("T", "T", "", "set text segment address (default -1)") + rootCmd.Flags().StringS("X", "X", "", "add string value definition of the form importpath.name=value") + rootCmd.Flags().BoolS("asan", "asan", false, "enable ASan interface") + rootCmd.Flags().BoolS("aslr", "aslr", false, "enable ASLR for buildmode=c-shared on windows (default true)") + rootCmd.Flags().StringS("benchmark", "benchmark", "", "set to 'mem' or 'cpu' to enable phase benchmarking") + rootCmd.Flags().StringS("benchmarkprofile", "benchmarkprofile", "", "emit phase profiles to base_phase.{cpu,mem}prof") + rootCmd.Flags().StringS("buildid", "buildid", "", "record id as Go toolchain build id") + rootCmd.Flags().StringS("buildmode", "buildmode", "", "set build mode") + rootCmd.Flags().BoolS("c", "c", false, "dump call graph") + rootCmd.Flags().StringS("capturehostobjs", "capturehostobjs", "", "capture host object files loaded during internal linking to specified dir") + rootCmd.Flags().BoolS("compressdwarf", "compressdwarf", false, "compress DWARF if possible (default true)") + rootCmd.Flags().StringS("cpuprofile", "cpuprofile", "", "write cpu profile to file") + rootCmd.Flags().BoolS("d", "d", false, "disable dynamic executable") + rootCmd.Flags().BoolS("debugnosplit", "debugnosplit", false, "dump nosplit call graph") + rootCmd.Flags().StringS("debugtextsize", "debugtextsize", "", "debug text section max size") + rootCmd.Flags().StringS("debugtramp", "debugtramp", "", "debug trampolines") + rootCmd.Flags().BoolS("dumpdep", "dumpdep", false, "dump symbol dependency graph") + rootCmd.Flags().StringS("extar", "extar", "", "archive program for buildmode=c-archive") + rootCmd.Flags().StringS("extld", "extld", "", "use linker when linking in external mode") + rootCmd.Flags().StringS("extldflags", "extldflags", "", "pass flags to external linker") + rootCmd.Flags().BoolS("f", "f", false, "ignore version mismatch") + rootCmd.Flags().BoolS("g", "g", false, "disable go package data checks") + rootCmd.Flags().BoolS("h", "h", false, "halt on error") + rootCmd.Flags().StringS("importcfg", "importcfg", "", "read import configuration from file") + rootCmd.Flags().StringS("installsuffix", "installsuffix", "", "set package directory suffix") + rootCmd.Flags().StringS("k", "k", "", "set field tracking symbol") + rootCmd.Flags().StringS("libgcc", "libgcc", "", "compiler support lib for internal linking") + rootCmd.Flags().StringS("linkmode", "linkmode", "", "set link mode") + rootCmd.Flags().BoolS("linkshared", "linkshared", false, "link against installed Go shared libraries") + rootCmd.Flags().StringS("memprofile", "memprofile", "", "write memory profile to file") + rootCmd.Flags().StringS("memprofilerate", "memprofilerate", "", "set runtime.MemProfileRate to rate") + rootCmd.Flags().BoolS("msan", "msan", false, "enable MSan interface") + rootCmd.Flags().StringS("n", "n", "", "symbol table") + rootCmd.Flags().StringS("o", "o", "", "write output to file") + rootCmd.Flags().StringS("pluginpath", "pluginpath", "", "full path name for plugin") + rootCmd.Flags().StringS("r", "r", "", "set the ELF dynamic linker search path to dir1:dir2:...") + rootCmd.Flags().BoolS("race", "race", false, "enable race detector") + rootCmd.Flags().BoolS("s", "s", false, "disable symbol table") + rootCmd.Flags().StringS("strictdups", "strictdups", "", "sanity check duplicate symbol contents during object file reading (1=warn 2=err)") + rootCmd.Flags().StringS("tmpdir", "tmpdir", "", "use directory for temporary files") + rootCmd.Flags().BoolS("v", "v", false, "print link trace") + rootCmd.Flags().BoolS("w", "w", false, "disable DWARF generation") + + // TODO extldflags completion + carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{ + "H": carapace.ActionValues("windowsgui"), // TODO other header types + "I": carapace.Batch( + carapace.ActionExecutables(), + carapace.ActionFiles(), + ).ToA(), + "L": carapace.ActionDirectories(), + "benchmark": carapace.ActionValues("mem", "cpu"), + "buildmode": golang.ActionBuildmodes(), + "cpuprofile": carapace.ActionFiles(), + "extar": carapace.Batch( + carapace.ActionExecutables(), + carapace.ActionFiles(), + ).ToA(), + "extld": carapace.Batch( + carapace.ActionExecutables(), + carapace.ActionFiles(), + ).ToA(), + "importcfg": carapace.ActionFiles(), + "libgcc": carapace.Batch( + carapace.ActionExecutables(), + carapace.ActionFiles(), + ).ToA(), + "linkmode": carapace.ActionValues("internal", "external", "auto"), + "memprofile": carapace.ActionFiles(), + "o": carapace.ActionFiles(), + "r": carapace.ActionDirectories().List(","), + "tmpdir": carapace.ActionDirectories(), + }) +} diff --git a/completers/go-tool-link_completer/main.go b/completers/go-tool-link_completer/main.go new file mode 100644 index 0000000000..7fcf45d94c --- /dev/null +++ b/completers/go-tool-link_completer/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/rsteube/carapace-bin/completers/go-tool-link_completer/cmd" + +func main() { + cmd.Execute() +} diff --git a/completers/go_completer/cmd/build.go b/completers/go_completer/cmd/build.go index 6327c39f53..0d9c28ab75 100644 --- a/completers/go_completer/cmd/build.go +++ b/completers/go_completer/cmd/build.go @@ -3,6 +3,7 @@ package cmd import ( "github.com/rsteube/carapace" "github.com/rsteube/carapace-bin/pkg/actions/tools/golang" + "github.com/rsteube/carapace-bridge/pkg/actions/bridge" "github.com/rsteube/carapace/pkg/style" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -63,10 +64,11 @@ func addBuildFlags(cmd *cobra.Command) { carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{ "C": carapace.ActionDirectories(), - "buildmode": carapace.ActionValues("archive", "c-archive", "c-shared", "default", "shared", "exe", "pie", "plugin"), + "buildmode": golang.ActionBuildmodes(), "buildvcs": carapace.ActionValues("true", "false", "auto").StyleF(style.ForKeyword), "compiler": carapace.ActionValues("gccgo", "gc"), "coverpkg": golang.ActionPackages().UniqueList(","), + "ldflags": bridge.ActionCarapaceBin("go", "tool", "link").Split(), "mod": carapace.ActionValues("readonly", "vendor", "mod"), "modfile": carapace.ActionFiles(".mod"), "n": carapace.ActionValues("1", "2", "3", "4", "5", "6", "7", "8"), diff --git a/go.mod b/go.mod index e47cca8fb3..6dc9ed1773 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.19 require ( github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 github.com/pelletier/go-toml v1.9.5 - github.com/rsteube/carapace v0.40.0-pre1 + github.com/rsteube/carapace v0.40.0 github.com/rsteube/carapace-bridge v0.1.3 github.com/rsteube/carapace-spec v0.9.1 github.com/spf13/cobra v1.7.0 diff --git a/go.sum b/go.sum index f22496cede..2219392eab 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,8 @@ github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCko github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rsteube/carapace v0.39.1/go.mod h1:jkLt41Ne2TD2xPuMdX/2O05Smhy8vMgG7O2TYvC0yOc= -github.com/rsteube/carapace v0.40.0-pre1 h1:vj5uSkyPO8lvPsFAYrOJa8BaRukv1YMzqUkbD5Bz5iM= -github.com/rsteube/carapace v0.40.0-pre1/go.mod h1:jkLt41Ne2TD2xPuMdX/2O05Smhy8vMgG7O2TYvC0yOc= +github.com/rsteube/carapace v0.40.0 h1:m6bZzMzjIezcCE0SEMF7WSug4BqlTaxHTq2qVC85RYI= +github.com/rsteube/carapace v0.40.0/go.mod h1:jkLt41Ne2TD2xPuMdX/2O05Smhy8vMgG7O2TYvC0yOc= github.com/rsteube/carapace-bridge v0.1.3 h1:M6+xOgSayXU6naT0zDhjpQhgTGAcoaVFqGdWn8BOm2o= github.com/rsteube/carapace-bridge v0.1.3/go.mod h1:BLmN9ceKEqlxl4MpcnSx9zU+2ITN1fwJfOVDCVV0g6I= github.com/rsteube/carapace-pflag v0.2.0 h1:EYqFO9Haib3NDCPqKu0VxOGi9YQBkXk1IzlHdT0M0vw= diff --git a/pkg/actions/tools/golang/buildmode.go b/pkg/actions/tools/golang/buildmode.go new file mode 100644 index 0000000000..a95a613284 --- /dev/null +++ b/pkg/actions/tools/golang/buildmode.go @@ -0,0 +1,20 @@ +package golang + +import "github.com/rsteube/carapace" + +// ActionBuildmodes completes build modes +// +// archive (Build the listed non-main packages into .a files) +// c-archive (Build the listed main package, plus all packages it imports, into a C archive file) +func ActionBuildmodes() carapace.Action { + return carapace.ActionValuesDescribed( + "archive", "Build the listed non-main packages into .a files", + "c-archive", "Build the listed main package, plus all packages it imports, into a C archive file", + "c-shared", "Build the listed main package, plus all packages it imports, into a C shared library", + "default", "Listed main packages are built into executables and listed non-main packages are built into .a files", + "shared", "Combine all the listed non-main packages into a single shared library", + "exe", "Build the listed main packages and everything they import into executables", + "pie", "Build the listed main packages and everything they import into position independent executables (PIE)", + "plugin", "Build the listed main packages, plus all packages that they import, into a Go plugin", + ) +}