From a5d61d75e3d314323d07914ae36daf69c96f0bf8 Mon Sep 17 00:00:00 2001
From: Dmitri Shuralyov <dmitshur@golang.org>
Date: Wed, 14 Feb 2024 19:08:02 -0500
Subject: [PATCH] runtime: deprecate GOROOT

Fixes #51473.

Change-Id: Ic868790f480b21b472c98b39be797bcffb1fa892
Reviewed-on: https://go-review.googlesource.com/c/go/+/564142
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
---
 api/next/51473.txt                          | 1 +
 doc/next/6-stdlib/99-minor/runtime/51473.md | 3 +++
 src/runtime/extern.go                       | 5 +++++
 3 files changed, 9 insertions(+)
 create mode 100644 api/next/51473.txt
 create mode 100644 doc/next/6-stdlib/99-minor/runtime/51473.md

diff --git a/api/next/51473.txt b/api/next/51473.txt
new file mode 100644
index 00000000000..c47a629d73f
--- /dev/null
+++ b/api/next/51473.txt
@@ -0,0 +1 @@
+pkg runtime, func GOROOT //deprecated #51473
diff --git a/doc/next/6-stdlib/99-minor/runtime/51473.md b/doc/next/6-stdlib/99-minor/runtime/51473.md
new file mode 100644
index 00000000000..9083766a4d6
--- /dev/null
+++ b/doc/next/6-stdlib/99-minor/runtime/51473.md
@@ -0,0 +1,3 @@
+The [GOROOT] function is now deprecated.
+In new code prefer to use the system path to locate the “go” binary,
+and use `go env GOROOT` to find its GOROOT.
diff --git a/src/runtime/extern.go b/src/runtime/extern.go
index 2019be4ddec..f8f81be8ef4 100644
--- a/src/runtime/extern.go
+++ b/src/runtime/extern.go
@@ -336,6 +336,11 @@ var defaultGOROOT string // set by cmd/link
 // GOROOT returns the root of the Go tree. It uses the
 // GOROOT environment variable, if set at process start,
 // or else the root used during the Go build.
+//
+// Deprecated: The root used during the Go build will not be
+// meaningful if the binary is copied to another machine.
+// Use the system path to locate the “go” binary, and use
+// “go env GOROOT” to find its GOROOT.
 func GOROOT() string {
 	s := gogetenv("GOROOT")
 	if s != "" {
-- 
GitLab