Skip to content

Commit 369b9b2

Browse files
committed
Merge remote-tracking branch 'upstream/microsoft/main' into dev/auto-sync/microsoft/main
2 parents 88c8640 + c01b007 commit 369b9b2

18 files changed

Lines changed: 2793 additions & 2977 deletions

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ jobs:
2323
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2424

2525
- name: Initialize CodeQL
26-
uses: github/codeql-action/init@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
26+
uses: github/codeql-action/init@38697555549f1db7851b81482ff19f1fa5c4fedc # v4.34.1
2727
with:
2828
languages: go
2929

3030
- name: Autobuild
31-
uses: github/codeql-action/autobuild@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
31+
uses: github/codeql-action/autobuild@38697555549f1db7851b81482ff19f1fa5c4fedc # v4.34.1
3232
with:
3333
working-directory: eng/_util
3434

3535
- name: Perform CodeQL Analysis
36-
uses: github/codeql-action/analyze@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
36+
uses: github/codeql-action/analyze@38697555549f1db7851b81482ff19f1fa5c4fedc # v4.34.1
3737
with:
3838
category: /language:go

.github/workflows/patch-build.yml

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,48 @@ concurrency:
1616
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
1717

1818
jobs:
19+
list_patches:
20+
name: Generate patch build matrix
21+
runs-on: ubuntu-latest
22+
outputs:
23+
patches: ${{ steps.list.outputs.patches }}
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
27+
28+
- name: Write patch matrix
29+
id: list
30+
run: pwsh eng/run.ps1 write-patch-matrix -github-actions
31+
1932
build_patches:
20-
name: Patches Build in Order
33+
name: "Build up to ${{ matrix.patch.name }}"
34+
needs: list_patches
2135
runs-on: ubuntu-latest
36+
strategy:
37+
matrix:
38+
patch: ${{ fromJson(needs.list_patches.outputs.patches) }}
2239
steps:
2340
- name: Checkout repository
2441
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2542
with:
2643
submodules: true
2744

28-
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
29-
with:
30-
go-version: '1.25'
31-
3245
- name: Set mock git config name/email
3346
run: |
3447
git config --global user.email "joe@blogs.com"
3548
git config --global user.name "Joe Blogs"
3649
37-
- name: Build patches
50+
- name: Apply patches 1-${{ matrix.patch.number }}
51+
run: pwsh eng/run.ps1 submodule-refresh -commits -take ${{ matrix.patch.number }}
52+
53+
- name: Build
3854
run: |
39-
for file in $(ls -v patches/*.patch); do
40-
echo "::group::Building $file"
41-
cd ${{ github.workspace }}/go
42-
git am --whitespace=nowarn ${{ github.workspace }}/$file
43-
cd ${{ github.workspace }}/go/src
44-
bash make.bash
45-
${{ github.workspace }}/go/bin/go mod vendor
46-
cd ${{ github.workspace }}/go/src/cmd
47-
${{ github.workspace }}/go/bin/go mod vendor
48-
cd ${{ github.workspace }}/go/src
49-
# Check if the vendor directory is clean
50-
git diff --exit-code vendor cmd/vendor || (echo "Vendor directories are not clean. Please run 'go mod vendor' in the appropriate directories and commit the changes." && exit 1)
51-
echo "::endgroup::"
52-
done
55+
set -x
56+
pwsh eng/run.ps1 build
57+
cd ${{ github.workspace }}/go/src
58+
${{ github.workspace }}/go/bin/go mod vendor
59+
cd ${{ github.workspace }}/go/src/cmd
60+
${{ github.workspace }}/go/bin/go mod vendor
61+
cd ${{ github.workspace }}/go/src
62+
# Check if the vendor directory is clean
63+
git diff --exit-code vendor cmd/vendor || (echo "Vendor directories are not clean. Please run 'go mod vendor' in the appropriate directories and commit the changes." && exit 1)

.github/workflows/test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
# time to hit the patch failure N times. However, the actual tests run in AzDO, so we can't
1212
# reasonably cancel them from here (GitHub Actions).
1313

14-
name: "Test"
14+
# The "0:" prefix makes this workflow's checks sort above the alphabetical AzDO stage names on the
15+
# PR checks list, so patch failures are immediately visible without scrolling.
16+
name: "0: Test"
1517

1618
on:
1719
pull_request:

README.md

Lines changed: 21 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -57,95 +57,27 @@ There are a few additional support resources internal to Microsoft:
5757

5858
## Download and install
5959

60-
We build the forked Go toolset with the following list of OS/Arch combinations:
61-
62-
* `linux_amd64`
63-
* `linux_armv6l`
64-
* `linux_arm64`
65-
* `windows_amd64`
66-
* `windows_arm64`
67-
* `darwin_amd64`
68-
* `darwin_arm64`
69-
70-
Visit the [Migration Guide](eng/doc/MigrationGuide.md) for guidance about how we
71-
recommend migrating existing Go projects to use the Microsoft build of Go. This
72-
guide also helps resolve commonly encountered issues.
73-
74-
The following sections list the ways to get the Microsoft build of Go.
75-
76-
> [!NOTE]
77-
> Don't see an option that works for you? Let us know!
78-
> File a GitHub issue, or comment on an existing issue in this tag:
79-
[![](https://img.shields.io/github/labels/microsoft/go/Area-Acquisition)](https://github.com/microsoft/go/labels/Area-Acquisition)
80-
81-
### Docker Container Images
82-
83-
**[microsoft/go-images](https://github.com/microsoft/go-images)** maintains and
84-
documents container images that are available on Microsoft Artifact Registry.
85-
86-
### Azure Linux
87-
88-
The **[Azure Linux](https://github.com/microsoft/azurelinux)** distribution
89-
includes the `golang` package, a build of this fork of Go.
90-
91-
For more information about how to manage the `systemcrypto` migration from 1.24
92-
to 1.25 in Azure Linux 3, see
93-
[the `systemcrypto` section of the Migration Guide](eng/doc/MigrationGuide.md#migration-to-systemcrypto).
94-
95-
### Ubuntu
96-
97-
To install the Microsoft build of Go using an Ubuntu package, first set up the [Linux package repository for Microsoft Products](https://learn.microsoft.com/en-us/linux/packages).
98-
Packages are available in the Ubuntu 22.04 and 24.04 repositories.
99-
100-
After the repository is added, install the Microsoft build of Go by running the following commands:
101-
102-
```bash
103-
sudo apt-get update && sudo apt-get install msft-golang
104-
```
105-
106-
### Azure Pipelines `GoTool@0` task
107-
108-
The [`GoTool@0`](https://learn.microsoft.com/azure/devops/pipelines/tasks/reference/go-tool-v0) Azure Pipelines build task supports installing the Microsoft build of Go.
109-
For more details, see [the GoTool@0 section of the Migration Guide](eng/doc/MigrationGuide.md#the-gotool0-azure-pipelines-task).
110-
111-
### The `go-install.ps1` script
112-
113-
The [cross-platform `go-install.ps1` script](https://github.com/microsoft/go-infra/tree/main/goinstallscript) installs the Microsoft build of Go.
114-
It can install specific versions or the latest releases.
115-
116-
If you use Azure Pipelines, try running the script in a [script step](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/cmd-line-v2?view=azure-pipelines) and pass the `-AzurePipelinePath` argument to automatically set up `go` in the environment for future steps.
117-
118-
### Binary archive
119-
120-
[Signed builds of Go](https://github.com/microsoft/go/blob/microsoft/main/eng/doc/Downloads.md)
121-
for several platforms are available as `zip` and `tar.gz` files.
122-
123-
### Build from source
124-
125-
#### Pre-patched source tarball
126-
127-
[The microsoft/go GitHub releases](https://github.com/microsoft/go/releases)
128-
include a source tarball file ending in `.src.tar.gz`. After downloading and
129-
extracting the tar.gz file, build it using the
130-
[upstream instructions](https://go.dev/doc/install/source).
131-
132-
> [!NOTE]
133-
> The `zip` file that GitHub offers for download on the [microsoft/go releases page](https://github.com/microsoft/go/releases) is incomplete: it doesn't include the `go` submodule.
134-
> Make sure to download the `.src.tar.gz` file instead, or [clone the repository using Git and set up the patched submodule](#clone-and-build).
135-
136-
#### Clone and build
137-
138-
First, clone this repository using Git and check out the desired tag or commit.
139-
140-
If you want to contribute to the Microsoft build of Go project, read the [Developer Guide](eng/doc/DeveloperGuide.md).
141-
It lists the steps we recommend to set up a Microsoft build of Go development environment, execute your first build, run the standard library test suite, and contribute a PR.
142-
143-
If you just want to build on your own machine, you may find it more
144-
convenient to use the tools provided by the `eng/run.ps1` script. We use this
145-
script for CI builds. See [eng/README.md](eng/README.md) for more details about
146-
`eng/run.ps1` and other repository infrastructure.
147-
148-
Once built, the Microsoft build of Go binary is found at `go/bin/go`.
60+
We build the Microsoft build of Go toolset with the following OS/Arch combinations:
61+
62+
| OS | `amd64` | `arm64` | `armv6l` |
63+
| --- | :---: | :---: | :---: |
64+
| `linux` ||||
65+
| `windows` ||| |
66+
| `darwin` (macOS) ||| |
67+
68+
Visit the [Migration Guide](eng/doc/MigrationGuide.md) for guidance about how we recommend migrating existing Go projects to use the Microsoft build of Go.
69+
This guide also helps resolve commonly encountered issues.
70+
71+
The [Installation](eng/doc/Installation.md) documentation contains sections describing each of the following installation methods:
72+
73+
* [Docker Container Images](eng/doc/Installation.md#docker-container-images)
74+
* [Azure Linux](eng/doc/Installation.md#azure-linux)
75+
* [Ubuntu](eng/doc/Installation.md#ubuntu)
76+
* [Azure Pipelines `GoTool@0` task](eng/doc/Installation.md#azure-pipelines-gotool0-task)
77+
* [GitHub Actions `setup-go` action](eng/doc/Installation.md#github-actions-setup-go-action)
78+
* [The `go-install.ps1` script](eng/doc/Installation.md#the-go-installps1-script)
79+
* [Binary archive](eng/doc/Installation.md#binary-archive)
80+
* [Build from source](eng/doc/Installation.md#build-from-source)
14981

15082
## Contributing
15183

eng/_util/cmd/build/build.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func main() {
4141
o := &options{}
4242

4343
flag.BoolVar(&o.SkipBuild, "skipbuild", false, "Disable building Go.")
44+
flag.BoolVar(&o.SkipBuildRace, "skipbuildrace", false, "Disable building Go with race detector.")
4445
flag.BoolVar(&o.Test, "test", false, "Enable running tests.")
4546
flag.BoolVar(&o.PackBuild, "packbuild", false, "Enable creating an archive of this build using upstream 'distpack' and placing it in eng/artifacts/bin.")
4647
flag.BoolVar(&o.PackSource, "packsource", false, "Enable creating a source archive using upstream 'distpack' and placing it in eng/artifacts/bin.")
@@ -78,13 +79,14 @@ func main() {
7879
}
7980

8081
type options struct {
81-
SkipBuild bool
82-
Test bool
83-
PackBuild bool
84-
PackSource bool
85-
CreatePDB bool
86-
Refresh bool
87-
Experiment string
82+
SkipBuild bool
83+
SkipBuildRace bool
84+
Test bool
85+
PackBuild bool
86+
PackSource bool
87+
CreatePDB bool
88+
Refresh bool
89+
Experiment string
8890

8991
TestJSONFlags *buildutil.TestJSONFlags
9092

@@ -202,7 +204,12 @@ func build(o *options) (err error) {
202204
// The race runtime requires cgo.
203205
// It isn't supported on arm or 386.
204206
// It's supported on arm64, but the official linux-arm64 distribution doesn't include it.
205-
if os.Getenv("CGO_ENABLED") != "0" && targetArch != "arm" && targetArch != "arm64" && targetArch != "386" {
207+
if !o.SkipBuildRace &&
208+
os.Getenv("CGO_ENABLED") != "0" &&
209+
targetArch != "arm" &&
210+
targetArch != "arm64" &&
211+
targetArch != "386" {
212+
206213
fmt.Println("---- Building race runtime...")
207214
err := runCommandLine(
208215
filepath.Join("..", "bin", "go"+executableExtension),

eng/_util/cmd/submodule-refresh/submodule-refresh.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
package main
66

77
import (
8+
"errors"
89
"flag"
910
"fmt"
11+
"io"
12+
"log"
1013
"os"
1114
"path/filepath"
1215

@@ -22,6 +25,7 @@ applies patches to the stage by default, or optionally as commits.
2225
var (
2326
commits = flag.Bool("commits", false, "Apply the patches as commits.")
2427
skipPatch = flag.Bool("skip-patch", false, "Skip applying patches.")
28+
take = flag.Int("take", -1, "Only apply the first N patches. -1 means apply all.")
2529
origin = flag.String("origin", "", "Use this origin instead of the default defined in '.gitmodules' to fetch the repository.")
2630
shallow = flag.Bool("shallow", false, "Clone the submodule with depth 1.")
2731
fetchBearerToken = flag.String("fetch-bearer-token", "", "Use this bearer token to fetch the submodule repository.")
@@ -75,8 +79,51 @@ func refresh(rootDir string) error {
7579
mode = patch.ApplyModeCommits
7680
}
7781

82+
if *take >= 0 {
83+
// The patch API applies all patches in a directory. To apply only the
84+
// first N, copy them into a temporary directory and point the config there.
85+
tmpDirRelative := filepath.Join("eng", "artifacts", "submodule-refresh", "patch-subset")
86+
tmpDir := filepath.Join(config.RootDir, tmpDirRelative)
87+
if err := os.RemoveAll(tmpDir); err != nil {
88+
return err
89+
}
90+
if err := os.MkdirAll(tmpDir, 0o777); err != nil {
91+
return err
92+
}
93+
i := 0
94+
if err := patch.WalkGoPatches(config, func(path string) error {
95+
if i >= *take {
96+
log.Printf("Not including patch %q\n", path)
97+
return nil
98+
}
99+
i++
100+
log.Printf("Taking patch %q\n", path)
101+
return copyFile(path, filepath.Join(tmpDir, filepath.Base(path)))
102+
}); err != nil {
103+
return err
104+
}
105+
if *take > i {
106+
return fmt.Errorf("-take %d exceeds number of patches (%d)", *take, i)
107+
}
108+
config.PatchesDir = tmpDirRelative
109+
}
110+
78111
if err := patch.Apply(config, mode); err != nil {
79112
return err
80113
}
81114
return nil
82115
}
116+
117+
func copyFile(src, dst string) error {
118+
in, err := os.Open(src)
119+
if err != nil {
120+
return err
121+
}
122+
defer in.Close()
123+
out, err := os.Create(dst)
124+
if err != nil {
125+
return err
126+
}
127+
_, copyErr := io.Copy(out, in)
128+
return errors.Join(copyErr, out.Close())
129+
}
Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,55 @@ func upgradeDependency(info *depsInfo) error {
145145
return nil
146146
}
147147

148-
var goBinary = sync.OnceValue(func() string {
149-
//lint:ignore SA1019 we want to know the binary that built us
150-
//nolint:staticcheck // deprecated okay
151-
path := filepath.Join(runtime.GOROOT(), "bin", "go")
148+
var repoRoot = sync.OnceValues(func() (string, error) {
149+
dir, err := os.Getwd()
150+
if err != nil {
151+
return "", fmt.Errorf("failed to get working directory: %w", err)
152+
}
153+
for {
154+
if _, err := os.Stat(filepath.Join(dir, ".git-go-patch")); err == nil {
155+
log.Printf("Found repo root: %s\n", dir)
156+
return dir, nil
157+
}
158+
parent := filepath.Dir(dir)
159+
if parent == dir {
160+
return "", fmt.Errorf("could not find repo root: no .git-go-patch file found in any ancestor directory")
161+
}
162+
dir = parent
163+
}
164+
})
165+
166+
var goBinary = sync.OnceValues(func() (string, error) {
167+
ext := ""
152168
if runtime.GOOS == "windows" {
153-
path += ".exe"
169+
ext = ".exe"
154170
}
171+
// Use the dev-built Go binary, if it exists.
172+
if root, err := repoRoot(); err == nil {
173+
path := filepath.Join(root, "go", "bin", "go"+ext)
174+
if _, err := os.Stat(path); err == nil {
175+
log.Printf("Using %s\n", path)
176+
return path, nil
177+
}
178+
}
179+
//lint:ignore SA1019 we want to know the binary that built us
180+
//nolint:staticcheck // deprecated okay
181+
path := filepath.Join(runtime.GOROOT(), "bin", "go"+ext)
155182
log.Printf("Using %s\n", path)
156-
return path
183+
return path, nil
157184
})
158185

159186
func runGoCmd(wd string, args ...string) error {
160-
cmd := exec.Command(goBinary(), args...)
161-
cmd.Dir = wd
187+
root, err := repoRoot()
188+
if err != nil {
189+
return err
190+
}
191+
binary, err := goBinary()
192+
if err != nil {
193+
return err
194+
}
195+
cmd := exec.Command(binary, args...)
196+
cmd.Dir = filepath.Join(root, wd)
162197
out, err := cmd.CombinedOutput()
163198
if err != nil {
164199
return fmt.Errorf("%q failed: %v: %s", cmd, err, out)

0 commit comments

Comments
 (0)