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

Go: add bazel build #16317

Merged
merged 47 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
393f6b7
Go: add gazelle-generated `BUILD` files
redsun82 Apr 24, 2024
4ca8faa
Go: introduce universal binaries on macOS
redsun82 Apr 25, 2024
7d9a68b
Go: wrap gazelle to regenerate from scratch and add header
redsun82 Apr 26, 2024
3ad9c02
Go: remove `go_sdk.host`
redsun82 Apr 26, 2024
925a2cc
Go: create whole extractor pack with bazel
redsun82 Apr 26, 2024
19b2e56
Go: group BUILD and dbscheme generation target
redsun82 Apr 26, 2024
bfa189e
Go: use a dbscheme generated during the build in `extractor-pack`
redsun82 Apr 26, 2024
146d84b
Go: rework makefile
redsun82 Apr 26, 2024
c8b0224
Merge branch 'main' into redsun82/go
redsun82 Apr 26, 2024
d98ccdf
Go: update workflow
redsun82 Apr 26, 2024
0f387ee
Go: add vendor update to `//go:gen`
redsun82 Apr 26, 2024
86d6b8e
Go: put back go setup
redsun82 Apr 26, 2024
d66494d
Go: update `go-tests-other-os.yml`
redsun82 Apr 26, 2024
b0758fd
Go: workaround for gazelle on macOS
redsun82 Apr 29, 2024
0dfd336
Go: fix `//go:gen` on windows
redsun82 Apr 29, 2024
6ec223c
Go: small cleanup in `Makefile`
redsun82 Apr 29, 2024
2f6dd2a
Go: refactor workflows with shared action
redsun82 Apr 29, 2024
f0f6c22
Go: fix regex in action for macOS
redsun82 Apr 29, 2024
1f78882
Go: make windows checks happy
redsun82 Apr 29, 2024
15bb846
Go: add workaround for extractor pack windows installer
redsun82 Apr 29, 2024
e7886d0
Bazel: add empty registry override
redsun82 Apr 29, 2024
cb85a75
Bazel: patch `apple_support` to avoid registering its toolchain
redsun82 Apr 29, 2024
2590d8a
Merge branch 'main' into redsun82/go
redsun82 Apr 30, 2024
608791f
Bazel/Go: use native cross compilation for fat binaries
redsun82 May 2, 2024
94212d1
Bazel/Go: remove `apple_support`
redsun82 May 2, 2024
a8d3226
Merge branch 'main' into redsun82/go
redsun82 May 2, 2024
12b9b80
Go: revert changes to `make` and CI to postpone them in a separate PR
redsun82 May 2, 2024
520a2c9
Merge branch 'main' into redsun82/go
redsun82 May 2, 2024
9055d95
Go: remove unused action (will be re-added later)
redsun82 May 2, 2024
ca2d94b
Fix go pattern in `.pre-commit-config.yaml`
redsun82 May 2, 2024
318d954
Go: make `//go:gen` not clear by default, and clean on `--force`
redsun82 May 2, 2024
4ae82ac
Go: add explanatory comment to `extractor` `BUILD` file
redsun82 May 2, 2024
0bc6934
Go: rename `pkg_files` to something less confusing
redsun82 May 2, 2024
abcd916
Go: write test go runtime version in a specific file
redsun82 May 2, 2024
1aafc37
Revert "Go: write test go runtime version in a specific file"
redsun82 May 2, 2024
76067cb
Go: skip `X:nocoverageredesign` printing by autobuilder built with bazel
redsun82 May 2, 2024
81dea9f
Merge branch 'main' into redsun82/go
redsun82 May 2, 2024
00baccb
Go: autoformat
redsun82 May 2, 2024
31c427e
Bazel/Go: add more explanation in `gen.py`
redsun82 May 3, 2024
8f0b884
Bazel/Go: be more specific in `go/extractor/BUILD.bazel` comments
redsun82 May 3, 2024
2132c7b
Bazel/Go: make `@codeql//go:gen` runnable from internal repo
redsun82 May 3, 2024
471303b
Bazel/Go: remove unneeded comment
redsun82 May 3, 2024
17990da
Update go/extractor/BUILD.bazel
redsun82 May 3, 2024
77128de
Bazel/Go: make installer work from internal repo and on windows
redsun82 May 3, 2024
cba4ba0
Merge branch 'main' into redsun82/go
redsun82 May 6, 2024
5b184c1
Bazel/Go: add some comments
redsun82 May 6, 2024
73df4fa
Go: fix Windows installation
redsun82 May 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 4 additions & 61 deletions .github/workflows/go-tests-other-os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ on:
- .github/workflows/go-tests-other-os.yml
- .github/actions/**
- codeql-workspace.yml
env:
GO_VERSION: '~1.22.0'

permissions:
contents: read
Expand All @@ -18,72 +16,17 @@ jobs:
name: Test MacOS
runs-on: macos-latest
steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
id: go

- name: Check out code
uses: actions/checkout@v4

- name: Set up CodeQL CLI
uses: ./.github/actions/fetch-codeql

- name: Enable problem matchers in repository
shell: bash
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'

- name: Build
run: |
cd go
make

- name: Cache compilation cache
id: query-cache
uses: ./.github/actions/cache-query-compilation
with:
key: go-qltest
- name: Test
run: |
cd go
make test cache="${{ steps.query-cache.outputs.cache-dir }}"
- name: Run tests
uses: ./go/actions/test

test-win:
if: github.repository_owner == 'github'
name: Test Windows
runs-on: windows-latest-xl
steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
id: go

- name: Check out code
uses: actions/checkout@v4

- name: Set up CodeQL CLI
uses: ./.github/actions/fetch-codeql

- name: Enable problem matchers in repository
shell: bash
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'

- name: Build
run: |
cd go
make

- name: Cache compilation cache
id: query-cache
uses: ./.github/actions/cache-query-compilation
with:
key: go-qltest

- name: Test
run: |
cd go
make test cache="${{ steps.query-cache.outputs.cache-dir }}"
- name: Run tests
uses: ./go/actions/test
51 changes: 3 additions & 48 deletions .github/workflows/go-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ on:
- .github/actions/**
- codeql-workspace.yml

env:
GO_VERSION: '~1.22.0'

permissions:
contents: read

Expand All @@ -28,51 +25,9 @@ jobs:
name: Test Linux (Ubuntu)
runs-on: ubuntu-latest-xl
steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
id: go

- name: Check out code
uses: actions/checkout@v4

- name: Set up CodeQL CLI
uses: ./.github/actions/fetch-codeql

- name: Enable problem matchers in repository
shell: bash
run: 'find .github/problem-matchers -name \*.json -exec echo "::add-matcher::{}" \;'

- name: Build
run: |
cd go
make

- name: Check that all Go code is autoformatted
run: |
cd go
make check-formatting

- name: Compile qhelp files to markdown
run: |
cd go
env QHELP_OUT_DIR=qhelp-out make qhelp-to-markdown

- name: Upload qhelp markdown
uses: actions/upload-artifact@v3
- name: Run tests
uses: ./go/actions/test
with:
name: qhelp-markdown
path: go/qhelp-out/**/*.md

- name: Cache compilation cache
id: query-cache
uses: ./.github/actions/cache-query-compilation
with:
key: go-qltest

- name: Test
run: |
cd go
make test cache="${{ steps.query-cache.outputs.cache-dir }}"
run-code-checks: true
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ repos:
entry: bazel run //:buildifier
pass_filenames: false

- id: go-gen
name: Check checked in generated files in go
files: go/.*
redsun82 marked this conversation as resolved.
Show resolved Hide resolved
language: system
entry: bazel run //go:gen
pass_filenames: false

- id: codeql-format
name: Fix QL file formatting
files: \.qll?$
Expand Down
7 changes: 6 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ local_path_override(

# see https://registry.bazel.build/ for a list of available packages

bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "platforms", version = "0.0.9")
bazel_dep(name = "rules_go", version = "0.47.0")
bazel_dep(name = "rules_pkg", version = "0.10.1")
bazel_dep(name = "rules_nodejs", version = "6.0.3")
bazel_dep(name = "rules_python", version = "0.31.0")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "abseil-cpp", version = "20240116.0", repo_name = "absl")
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json")
bazel_dep(name = "fmt", version = "10.0.0")
bazel_dep(name = "gazelle", version = "0.36.0")

bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)

Expand Down Expand Up @@ -52,6 +54,9 @@ node.toolchain(
)
use_repo(node, "nodejs", "nodejs_toolchains")

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.22.2") # default
Copy link
Member

@mbg mbg May 2, 2024

Choose a reason for hiding this comment

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

Note: I assume this now replaces the GO_VERSION environment variables in the workflows, so we should update the playbook accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed, I will open a PR for that!

criemen marked this conversation as resolved.
Show resolved Hide resolved

register_toolchains(
"@nodejs_toolchains//:all",
)
119 changes: 119 additions & 0 deletions go/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
load("@gazelle//:def.bzl", "gazelle")
load("@rules_pkg//pkg:install.bzl", "pkg_install")
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files")
load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
load("//:defs.bzl", "codeql_platform")

gazelle(
name = "gazelle",
extra_args = ["go/extractor"],
)

_gen_binaries = [
"@rules_go//go",
":gazelle",
"//go/extractor/cli/go-gen-dbscheme",
]

py_binary(
name = "gen",
srcs = ["gen.py"],
args = ["$(rlocationpath %s)" % bin for bin in _gen_binaries],
data = _gen_binaries,
deps = ["@rules_python//python/runfiles"],
)

# this is an internal copy of the dbscheme to be used by extractor-pack
redsun82 marked this conversation as resolved.
Show resolved Hide resolved
# this allows the extractor-pack target to be independent and up-to-date with respect to
# having run //go:gen to update the checked in files
genrule(
name = "dbscheme",
outs = ["go.dbscheme"],
cmd = "$(execpath //go/extractor/cli/go-gen-dbscheme) $@",
tools = ["//go/extractor/cli/go-gen-dbscheme"],
)

pkg_files(
name = "resources",
srcs = [
"LICENSE",
"codeql-extractor.yml",
"ql/lib/go.dbscheme.stats",
":dbscheme",
],
)

pkg_filegroup(
name = "extractor-pack-generic",
srcs = [
":resources",
"//go/codeql-tools",
"//go/downgrades",
"//go/extractor:tokenizer",
],
visibility = ["//visibility:public"],
)

pkg_files(
name = "extractor-pack-arch",
srcs = [
"//go/extractor/cli/go-autobuilder",
"//go/extractor/cli/go-bootstrap",
"//go/extractor/cli/go-build-runner",
"//go/extractor/cli/go-extractor",
"//go/extractor/cli/go-gen-dbscheme",
"//go/extractor/cli/go-tokenizer",
],
attributes = pkg_attributes(mode = "0755"),
criemen marked this conversation as resolved.
Show resolved Hide resolved
prefix = "tools/" + codeql_platform,
visibility = ["//visibility:public"],
)

pkg_filegroup(
name = "extractor-pack",
srcs = [
":extractor-pack-arch",
":extractor-pack-generic",
],
visibility = ["//visibility:public"],
)

pkg_install(
name = "_extractor-pack-installer",
srcs = [":extractor-pack"],
)

# rules_pkg installer is currently broken on Windows
# see https://github.com/bazelbuild/rules_pkg/issues/387
# for now, work around it using an archive
pkg_zip(
criemen marked this conversation as resolved.
Show resolved Hide resolved
name = "_extractor-pack-zip",
srcs = [":extractor-pack"],
)

alias(
name = "_create-extractor-pack-arg",
actual = select({
"@platforms//os:windows": ":_extractor-pack-zip",
"//conditions:default": ":_extractor-pack-installer",
}),
)

py_binary(
name = "create-extractor-pack",
srcs = ["create_extractor_pack.py"],
args = ["$(rlocationpath :_create-extractor-pack-arg)"],
data = [":_create-extractor-pack-arg"],
main = "create_extractor_pack.py",
deps = ["@rules_python//python/runfiles"],
)

native_binary(
name = "gen-dbscheme",
src = "//go/extractor/cli/go-gen-dbscheme",
out = "go-gen-dbscheme",
args = [
"$$BUILD_WORKSPACE_DIRECTORY/go/ql/lib/go.dbscheme",
criemen marked this conversation as resolved.
Show resolved Hide resolved
],
)