microsoft / microsoft/go

Document the process to build Go application targeting an old glibc and cross-build using .NET shared images

Open
#1,866 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
Dominant language
Go
Stars
431
Forks
44
Avg merge
21h 18m
Merged PRs (30d)
30

Description

To make it easier to read (and public 🙂), here are the most critical parts from my raw notes about how I got a program to depend on an old glibc and how to build systemcrypto cross-arch.

Overview of this approach: .NET Linux build methodology

https://github.com/dotnet/dotnet-buildtools-prereqs-docker builds the images that include a rootfs.

Usage guides:
https://github.com/dotnet/runtime/blob/main/docs/workflow/using-docker.md
https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/containers.md

I used meta-build code like this to drive a properly configured go build command:

cmd.Env = append(
	os.Environ(),
	"GOEXPERIMENT=systemcrypto",
	"CGO_ENABLED=1",
	"GOOS="+goOS,
	"GOARCH="+goArch,
)
if *sysroot != "" {
	var linuxArch string
	switch goArch {
	case "amd64":
		linuxArch = "x86_64"
	case "arm64":
		linuxArch = "aarch64"
	default:
		return fmt.Errorf("unsupported architecture %q for sysroot", goArch)
	}
	ccPlatform := linuxArch + "-linux-gnu"
	cmd.Env = append(
		cmd.Env,
		// Set up for the compiler we expect to see in azurelinux-3.0-cross-* images.
		"CC="+joinSpace(
			"clang",
			"--target="+ccPlatform,
			"--sysroot="+*sysroot,
		),
		"CGO_LDFLAGS="+joinSpace(
			// Use lld: ld is not present.
			"-fuse-ld=lld",
		),
	)
}

In the pipeline yml, I used these containers:

    containers:
      cross-amd64:
        image: mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net10.0-cross-amd64
      cross-arm64:
        image: mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net10.0-cross-arm64

On linux amd64: -sysroot /crossrootfs/x64
On linux arm64: -sysroot /crossrootfs/arm64

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked .NET Linux build methodology, Docker prereqs repository, and runtime container guides. Use the provided Go environment snippet, pipeline YAML, cross-image names, and sysroot paths as source material for a public guide covering old-glibc and amd64/arm64 systemcrypto builds. Done means the process, commands, links, and platform-specific paths are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go, linux
Domain
build-system, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.