Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Goのビルドシステムの変遷 / The history of Go's build system

Avatar for ymotongpoo ymotongpoo
September 27, 2025

Goのビルドシステムの変遷 / The history of Go's build system

Go Conference 2025の登壇資料です
https://gocon.jp/2025/talks/952323/

Avatar for ymotongpoo

ymotongpoo

September 27, 2025
Tweet

More Decks by ymotongpoo

Other Decks in Technology

Transcript

  1. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 1 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Goのビルドシステムの変遷 Yoshi Yamaguchi (@ymotongpoo) G O C O N F E R E N C E 2 0 2 5 D A Y 2 Senior Developer Advocate Amazon Web Services Japan, G.K.
  2. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 2 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. ⾃⼰紹介 ⼭⼝ 能迪(やまぐち よしふみ) アマゾンウェブサービスジャパン合同会社 シニアデベロッパーアドボケイト 専⾨領域 • オブザーバビリティ • SRE全般 @ymotongpoo
  3. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 3 もくじ 1. はじめに 2. makefile 3. goinstall 4. go build 5. Go Module 6. module mirror & checksum database (GOPROXY) 7. Go Workspace 8. go mod tools
  4. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 4 これ、20分でいけんの︖
  5. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 5 だいぶ無理なんで、このへんはカットしました(謝罪) • gccgo などの gc 以外のビルド • コンパイラのセルフホスト • //go:xxxx などのビルドタグ • go build -buildmode • PGO(プロファイルガイド付き最適化) • 外部ツールによるビルド(例: ko, gazelle) スライドを共有したXのポストにいいねが多く集まるようだったら 同⼈誌かなにかで完全版書くかも
  6. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 6 Go OSS化 2009/11 2010/02 goinstall go get (Go 1.0) 2012/03 2015/08 vendoring (Go 1.5) 2013/09 godep gopkg.in 2014/03 glide 2014/07 gb 2015/04 2016/01 dep 2018/02 vgo 2018/08 Modules (Go 1.11) Proxy & Sum DB (Go 1.13) 2019/09 2022/03 Workspace (Go 1.18) 2025/09 Go Conference 2025 (Go 1.25) 年表
  7. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 7 むかし むかし あるところに…
  8. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 8 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. はじめに
  9. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 9 Go ができたきっかけ GopherConAU 2019 - Carmen Andoh - 10 Years of GO
  10. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 10 Go でのパッケージ 初期 $GOPATH/ pkg/ bin/ src/ hello/ hello.go hola.go github.com/foo/bar hoge.go piyo.go Go Module 以後 $root/ go.mod go.sum hello/ hello.go hola.go
  11. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 11 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Makefile (weekly-release, rXX)
  12. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 12 Makefile だった頃 6g, 6l, 6c, 6a を make で叩くようにする便利スクリプトを配布 # Copyright 2009 The Go Authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. include $(GOROOT)/src/Make.inc TARG=hello GOFILES=\ hello.go\ hola.go\ include $(GOROOT)/src/Make.pkg
  13. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 13 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. goinstall (pre Go 1.0)
  14. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 14 go コマンドが存在していない • ⾃分でGOPATH以下に依存パッケージを配置しなければいけないのは⼤変 • Makefile 書きたくない • まだ安定版でない(r58とか)なので、ソースごとに対応バージョンが異なる
  15. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 15 goinstall コマンドの実験的リリース 2010年2⽉ にRuss Coxが goinstall をリリース • いまの go install とは異なる • go get に相当 • go.rXX のタグを参照 https://groups.google.com/g/golang-nuts/c/8JFwR3ESjjI/m/cy7qZzN7Lw4J
  16. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 16 パッケージの共有を公開VCSで⾏う⼿法の確⽴ • これまでは⾃由に公開されていたパッケージ構成に規約のようなものが⽣まれる • Go 1.0 に向けた⼟壌が整う • 同時期に並⾏して gofix、gofmt、godoc といったツールも公開される
  17. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 17 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. go get, go build (Go 1.0)
  18. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 18 Go 1リリース 2012年3⽉18⽇にGo 1がリリースされる(=後⽅互換性の開始) go コマンドが導⼊される Go 1 Release Notes - The go command
  19. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 19 設定より規約 Convention over configuration go get や go build により Makefile の記述や⼿動によるパッケージの配置を排除 Go⾔語の開発当初より実現したかった理想を具現化 About the go command - The Go Programming Language $GOPATH/ pkg/ bin/ src/ main.go github.com/foo/hello hello.go hola.go
  20. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 20 パッケージのバージョンに関するFAQ (Go 1.2-1.10) How should I manage package versions using "go get"? ”Go get" does not have any explicit concept of package versions. Versioning is a source of significant complexity, especially in large code bases, and we are unaware of any approach that works well at scale in a large enough variety of situations to be appropriate to force on all Go users. What "go get" and the larger Go toolchain do provide is isolation of packages with different import paths. For example, the standard library's html/template and text/template coexist even though both are "package template". This observation leads to some advice for package authors and package users. 意訳: バージョン管理を導⼊するとおかしくなるから、必要なものの必要な状態はすべてスナップショットを リポジトリに⼊れとけ
  21. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 21 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. vendoring (Go 1.5)
  22. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 22 依存パッケージのバージョン衝突問題 main.go と cat と dog が animal に依存している場合を考える $GOPATH/ src/ main.go github.com/foo/cat main.go github.com/foo/dog main.go github.com/foo/animal bark.go run.go これのバージョンは︖
  23. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 23 局所解としての “go1” タグ 外部に公開するリビジョンを固定し、依存しているパッケージに破壊的変更に対応 する期間を設ける 要約: リポジトリに go1 というブランチやタグがあれば go get の際にそれを取得し、なければ リモートの HEAD を取得する go command - cmd/go - Go Packages (go1.4)
  24. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 24 ユーザーからのフィードバック ユーザーは他⾔語での経験から、パッケージのバージョンロック機構を求め、コミ ュニティでのワーキンググループも発⾜ Go package management goals - Google Docs
  25. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 25 暫定解としてのvendoring (Go 1.5) $GOPATH/ src/ main.go github.com/foo/cat main.go vendor/ github.com/foo/animal github.com/foo/dog main.go vendor/ github.com/foo/animal github.com/foo/animal v1 v2 v3 各パッケージはvendor配下のコピーを優先して 参照する
  26. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 26 依然として不満の声は収まらず • vendor 以下への配置は⼿動で⾏う必要がある • どのバージョンに依存しているか⼀⾒してわからない • そもそもコピーをリポジトリに⼊れたくない • 依存バージョンがわかれば⾃動で取って来れるだろ
  27. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 27 コミュニティからのアンサー (Go 1.2-1.7くらい) • godep (2013年9⽉公開) • JSONで依存パッケージ情報を、リビジョン決め打ちで保存。独⾃のvendorディレクトリにコピ ーを保存。 • gopkg.in (2014年3⽉公開) • リポジトリの特定のリビジョンに対しメジャーバージョンを固定するリダイレクト⽤のURLを 作成することでメジャーバージョンの固定を促す仕組み。セマンティックバージョニングの⽅ 向性について重要な意味をもたらした。 • glide (2014年7⽉公開) • yamlで依存パッケージ情報を保存。npmやpipのようにある程度バージョンに幅を持たせて指定 可能。lockファイルで現時点で⼊れられているリビジョンを記録。Go公式のvendorディレクト リに保存。 • gb (2015年4⽉公開) • manifestファイルに依存パッケージと依存リビジョンを記録。独⾃のvendorディレクトリにコ ピーを保存。
  28. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 28 Go teamからのアンサー • dep (2016年3⽉公開) • godep の後継。Go teamによる開発で⾏われた。tomlで依存パッケージ情報を保存。バージョ ン幅に余裕を持たせて指定可能。lockファイルはリビジョンを記録。GOPATHでのディレクト リ構造を踏襲。Go公式のvendorディレクトリに保存。
  29. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 29 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Go Modules (Go 1.10-1.13)
  30. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 30 Russ Coxによる考察とGo公式の⽅向性 2018年2⽉にGoにおけるパッケージのバージョン管理に関して、7本におよぶ記事 (補⾜のために追加で4本の解説記事もある) https://research.swtch.com/vgo
  31. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 31 いろいろ問題を整理した • go get ではバージョン管理の概念がなく、再現性のあるビルドができなかった • go get はリポジトリのリリースタグを無視していた • go get は VCS ツールを⼊れてないとパッケージを取得できなかった • セマンティックバージョンに関して明確なガイドがなかった • vendoringではパッケージのバージョンを管理するためには役に⽴たなかった • 3pツールの互換性がなかった • GOPATHでは複数のバージョンを管理できなかった • GOPATHをプロジェクトごとに使うワークフローがうまく機能しないことがある
  32. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 32 vgo: モジュール機能の試験的ツール (Go 1.10) • 先に挙がっていたような問題をすべて解決する実装 • dep からの公式の移⾏先
  33. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 33 Go Modules (Go 1.11-1.13) vgo での学びと成功を受けて Go Modules を正式にリリース • コマンドを go mod として go ツールに統合 • go.mod と go.sum に標準化し、vendorへの依存の廃⽌ • モジュールキャッシュの導⼊ ※ Go 1.11 ではベータリリースで環境変数 GO111MODULE=on にする必要があった。 Go 1.13 からデフォルトが on になり GOPATH モードは⾮推奨に。
  34. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 34 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Module mirror & Checksum DB (Go 1.13-1.15)
  35. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 35 Go Modulesの正式リリースからの学び https://go.dev/blog/modules2019
  36. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 36 Go Modulesによって出現した新たな課題 パッケージのバージョン管理問題はまだ解決していなかった • 依存パッケージのリポジトリが落ちるとビルドできなくなる • リポジトリのタグが強制変更されるとビルドの再現性がなくなる • リポジトリに多⼤な負荷がかかる可能性があった
  37. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 37 Module mirror & Checksum DB (Go 1.13) • 中央でモジュールをキャッシュし、go modはデフォルトそちらを参照 • なければオリジナルのリポジトリを⾒に⾏き、キャッシュしてからダウンロード • SHA256 ハッシュを確認しチェックサムDBに保存 https://go.dev/blog/module-mirror-launch
  38. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 38 GOPROXY, GOSUMDB デフォルト設定は次の通りで、⾃分で⽤意することも可能 GOPROXY="https://proxy.golang.org" GOSUMDB="sum.golang.org" c.f. https://github.com/gomods/athens
  39. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 39 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Go Workspace (Go 1.18)
  40. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 40 プロポーザルの解説動画 https://youtu.be/wQglU5aB5NQ
  41. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 41 モジュール開発者のための新たなワークフロー Go 1.13でのリリース以降、モジュールに関する機能は落ち着いてきたが、依存関 係にある複数モジュールを同時に開発する場合に不便があった • go.mod で頻繁に replace を編集する必要があった • ブランチを変更すると壊れたりした • モジュールが独⽴したものを開発することしか意図してなかった
  42. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 42 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. まとめ
  43. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 43 まとめ • Go は⻑い時間をかけてビルドシステムを改善してきた • 途中でコンパイラがセルフホストされた • 途中でジェネリクスも導⼊された • それでも後⽅互換性を壊さずにそれを⾏ってきた • しばらくビルドシステムに関する⼤きな変更が起きていない
  44. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 45 Thank you! © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Yoshi Yamaguchi @ymotongpoo Any questions?