diff --git a/docs/settings.md b/docs/settings.md
index 468bfb3a44..2d3c4cb771 100644
--- a/docs/settings.md
+++ b/docs/settings.md
@@ -483,6 +483,22 @@ Default: `"proxy"`
The path to the `go` binary used to install the Go tools. If it's empty, the same `go` binary chosen for the project will be used for tool installation.
Default: `""`
+
+### `go.toolsManagement.buildFlags`
+
+Flags to `go install` used to install the Go tools. (e.g. `["-ldflags", "-s -w"]`)
+
+Default: `[]`
+### `go.toolsManagement.buildTags`
+
+The Go build tags used to install the Go tools.
+
+Default: `""`
+### `go.toolsManagement.envVars`
+
+Environment variables that will be used to install the Go tools.
+
+Default: `{}`
### `go.trace.server`
Trace the communication between VS Code and the Go language server.
diff --git a/extension/package.json b/extension/package.json
index 3b28880a7d..4a098089c0 100644
--- a/extension/package.json
+++ b/extension/package.json
@@ -114,6 +114,9 @@
"go.inferGopath",
"go.toolsGopath",
"go.toolsEnvVars",
+ "go.toolsManagement.buildFlags",
+ "go.toolsManagement.buildTags",
+ "go.toolsManagement.envVars",
"go.toolsManagement.go"
]
}
@@ -1544,6 +1547,27 @@
"description": "Automatically update the tools used by the extension, without prompting the user.",
"scope": "resource"
},
+ "go.toolsManagement.buildFlags": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "default": [],
+ "description": "Flags to `go install` used to install the Go tools. (e.g. [\"-ldflags\", \"-s -w\"])",
+ "scope": "machine-overridable"
+ },
+ "go.toolsManagement.buildTags": {
+ "type": "string",
+ "default": "",
+ "description": "The Go build tags used to install the Go tools.",
+ "scope": "machine-overridable"
+ },
+ "go.toolsManagement.envVars": {
+ "type": "object",
+ "default": {},
+ "description": "Environment variables that will be used to install the Go tools.",
+ "scope": "machine-overridable"
+ },
"go.enableCodeLens": {
"type": "object",
"properties": {
diff --git a/extension/src/goInstallTools.ts b/extension/src/goInstallTools.ts
index 490e77573c..9ba54af706 100644
--- a/extension/src/goInstallTools.ts
+++ b/extension/src/goInstallTools.ts
@@ -263,7 +263,8 @@ async function installToolWithGo(
}
}
- const env = Object.assign({}, envForTools);
+ const toolsBuildEnv = getGoConfig().get('toolsManagement.envVars') ?? {};
+ const env = Object.assign({}, envForTools, toolsBuildEnv);
let version: semver.SemVer | string | undefined | null = tool.version;
if (!version && tool.usePrereleaseInPreviewMode && extensionInfo.isPreview) {
@@ -291,9 +292,21 @@ async function installToolWithGoInstall(goVersion: GoVersion, env: NodeJS.Dict 0 && buildFlags.indexOf('-tags') === -1) {
+ buildArgs.push('-tags');
+ buildArgs.push(buildTags);
+ }
+ buildArgs.push(importPath);
+
const execFile = util.promisify(cp.execFile);
outputChannel.trace(`$ ${goBinary} install -v ${importPath}} (cwd: ${opts.cwd})`);
- await execFile(goBinary, ['install', '-v', importPath], opts);
+ await execFile(goBinary, buildArgs, opts);
}
export function declinedToolInstall(toolName: string) {