Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add arm/v6 cross-compiled build #523

Merged
merged 4 commits into from
Apr 20, 2022

Conversation

dagood
Copy link
Member

@dagood dagood commented Apr 12, 2022

Includes related changes:

  • Update bootstrap Go to 1.18 for strings.Cut.
  • Add missing err checks in pack code.
  • Diff reduction: include directory entries in the tar.gz/zip, use / rather than \ for zips even though they're for Windows.

To check the results, I cherry-picked to 1.18 and compared the file lists on the platforms we're currently building:

#> diff <(tar -tf go1.18.linux-amd64.tar.gz | sort) <(tar -tf eng/artifacts/bin/go.dev.linux-amd64.tar.gz | sort)
29d28
< go/codereview.cfg

#> diff <(tar -tf go1.18.linux-armv6l.tar.gz | sort) <(tar -tf eng/artifacts/bin/go.dev.linux-armv6l.tar.gz | sort)
29d28
< go/codereview.cfg
802d800
< go/pkg/linux_arm/os/signal/
804,805d801
< go/pkg/linux_arm/os/signal/internal/
< go/pkg/linux_arm/os/signal/internal/pty.a
821d816
< go/pkg/linux_arm/runtime/cgo.a

# (Copied from a non-cross build on a Windows machine.)
#> diff <(unzip -Z1 go1.18.windows-amd64.zip | sort) <(unzip -Z1 eng/artifacts/bin/go.dev.windows-amd64.zip | sort)
29d28
< go/codereview.cfg
598d596
< go/pkg/tool/windows_amd64/api.exe
11366,11367c11364,11365
< go/test/fixedbugs/issue27836.dir/Äfoo.go
< go/test/fixedbugs/issue27836.dir/Ämain.go
---
> go/test/fixedbugs/issue27836.dir/├Дfoo.go
> go/test/fixedbugs/issue27836.dir/├Дmain.go
  • Missing go/codereview.cfg is normal.
  • go/pkg/linux_arm/os/signal/internal/pty.a is interesting. According to the source, it's only used to run tests.
  • go/pkg/linux_arm/runtime/cgo.a is probably missing because of the cross-compile: something like not being able to build cgo without running a C compiler that targets arm/v6. This might not be an issue, because when someone needs cgo their copy of Go might automatically build cgo if this .a prebuilt file is missing.
    • Building a simple cgo app works fine without this file. When I run go tool dist test, this file is built.
  • go/pkg/tool/windows_amd64/api.exe is an existing diff. I think it's actually an upstream bug--filed x/build/cmd/release: Windows zip/installer includes unnecessary pkg/tool/windows_amd64/api.exe golang/go#52335
  • go/test/fixedbugs/issue27836.dir/├Дfoo.go is an existing diff, not new to this change. However, it seems to only be a problem with unzip -Z1. When I extract the file on Windows, it ends up being Ä, not ├Д.

As a very basic check that the cross-compiled Go works, I installed Debian Bullseye armhf (arm/v7) onto my RPi 4 (arm64 chip), and on there, the armv6l build from CI works to:

  • Build a basic app that uses cgo
  • Run go tool dist test.

Our partners are going to be using armhf, so this is probably good enough for now.

@dagood dagood force-pushed the dev/dagood/cross-arm branch 2 times, most recently from 43e1064 to f0c8178 Compare April 13, 2022 20:49
Update bootstrap Go to 1.18 for strings.Cut.

Add missing err checks in pack code.
@dagood dagood force-pushed the dev/dagood/cross-arm branch from f0c8178 to a5fa7c1 Compare April 13, 2022 20:54
@dagood dagood marked this pull request as ready for review April 13, 2022 21:07
@dagood dagood requested a review from a team as a code owner April 13, 2022 21:07
@dagood dagood requested review from jaredpar, qmuntal and chsienki April 13, 2022 23:23
eng/utilities.ps1 Outdated Show resolved Hide resolved
# we need to be able to run the tool on the host, so we must always target the host OS/ARCH. Clear
# out the GOOS/GOARCH values (empty string) to detect host OS/ARCH automatically for the tools.
Invoke-CrossGoBlock "" "" {
Write-Host "In '$tool_module', building '$module_local_script_path' -> $tool_output"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to be careful about is how block execution and variable scoping works in powershell. I've gotten burned by this in the past because I made bad assumptions about how name lookup works here. IIRC the variables are not actually captured, aka it's not a lambda, but instead the variable lookup occurs in the context where the block is evaluated.

Been many years since I got burned here so maybe I'm having bad memory but I would look into this a bit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, no capturing.

In this particular case, capture vs. non-capture doesn't have any impact because Invoke-CrossGoBlock doesn't set any variables that are being used in the block, the block is defined right here where it's being passed to the function, and the block doesn't escape. But definitely something to be aware of while modifying these scripts.

I could inline Invoke-CrossGoBlock to avoid the weirdness, but we rely on blocks for Invoke-WithRetry too, so it wouldn't really remove the need to know about this quirk.

I'm glad we're able to get out of this script and into the _core Go module relatively quickly. 😄

eng/_core/cmd/build/build.go Show resolved Hide resolved
@dagood
Copy link
Member Author

dagood commented Apr 14, 2022

I ran an internal build on the latest commit: https://dev.azure.com/dnceng/internal/_build/results?buildId=1718680&view=results, and I tried ingesting it into go-images, but there are a couple things to fix:

The build asset json lists the build as "env": { "GOARCH": "armv6l", "GOOS": "linux" }, but it should be "GOARCH": "arm", "GOARM": "6". This requires a fix to go-infra and updating the version in eng/_util, so I'll fix that in this PR.

The dockerupdate command doesn't update the manifest.json file quite right. This fix is just on the go-infra side.

@dagood
Copy link
Member Author

dagood commented Apr 20, 2022

Build asset JSON from new dev internal build looks good: https://dev.azure.com/dnceng/internal/_build/results?buildId=1727301&view=results. Generates expected armhf results in go-images with latest dockerupdate.

@dagood dagood merged commit 41afc84 into microsoft:microsoft/main Apr 20, 2022
@dagood dagood deleted the dev/dagood/cross-arm branch April 20, 2022 16:53
dagood added a commit to dagood/go that referenced this pull request Apr 20, 2022
* Add arm/v6 cross-compiled build

Update bootstrap Go to 1.18 for strings.Cut.

Add missing err checks in pack code.

* Use 'finally' in Invoke-CrossGoBlock

* Explain getEnvOrDefault error case in doc comment

* Update go-infra for build asset JSON arm/v6 fix

(cherry picked from commit 41afc84)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants