Skip to content

Commit

Permalink
added go-tool-link
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jul 26, 2023
1 parent a8f6fe0 commit 312912e
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 4 deletions.
101 changes: 101 additions & 0 deletions completers/go-tool-link_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -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(),
})
}
7 changes: 7 additions & 0 deletions completers/go-tool-link_completer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/rsteube/carapace-bin/completers/go-tool-link_completer/cmd"

func main() {
cmd.Execute()
}
4 changes: 3 additions & 1 deletion completers/go_completer/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
20 changes: 20 additions & 0 deletions pkg/actions/tools/golang/buildmode.go
Original file line number Diff line number Diff line change
@@ -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",
)
}

0 comments on commit 312912e

Please sign in to comment.