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 1 commit
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ build:linux --cxxopt=-std=c++20
build:macos --cxxopt=-std=c++20 --cpu=darwin_x86_64
build:windows --cxxopt=/std:c++20 --cxxopt=/Zc:preprocessor

# this requires developer mode, but is required to have pack installer functioning
common:windows --windows_enable_symlinks --enable_runfiles
criemen marked this conversation as resolved.
Show resolved Hide resolved

common --registry=file:///%workspace%/misc/bazel/registry
common --registry=https://bcr.bazel.build

Expand Down
24 changes: 3 additions & 21 deletions go/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
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")

native_binary(
Expand Down Expand Up @@ -81,31 +80,14 @@ pkg_filegroup(
)

pkg_install(
name = "_extractor-pack-installer",
name = "_extractor_pack",
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(
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"],
env = {"REPO_NAME": repo_name()},
main = "create_extractor_pack.py",
deps = ["@rules_python//python/runfiles"],
deps = ["_extractor_pack"],
)
24 changes: 10 additions & 14 deletions go/create_extractor_pack.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
#!/usr/bin/env python3
import os
import pathlib
import shutil
import sys
import subprocess
import zipfile
from python.runfiles import runfiles

try:
workspace_dir = pathlib.Path(os.environ['BUILD_WORKSPACE_DIRECTORY'])
except KeyError:
print("this should be run with bazel run", file=sys.stderr)
sys.exit(1)
res = subprocess.run(["bazel", "run", ":create-extractor-pack"], cwd=pathlib.Path(__file__).parent)
sys.exit(res.returncode)

dest_dir = workspace_dir / 'go' / 'build' / 'codeql-extractor-go'
installer_or_zip = pathlib.Path(runfiles.Create().Rlocation(sys.argv[1]))
from go._extractor_pack_install_script import main

shutil.rmtree(dest_dir, ignore_errors=True)
if os.environ['REPO_NAME'] == 'codeql~':
workspace_dir /= 'ql'

if installer_or_zip.suffix == '.zip':
dest_dir.mkdir()
with zipfile.ZipFile(installer_or_zip) as pack:
pack.extractall(dest_dir)
else:
os.environ['DESTDIR'] = str(dest_dir)
subprocess.check_call([installer_or_zip])
dest_dir = workspace_dir / 'go' / 'build' / 'codeql-extractor-pack'
shutil.rmtree(dest_dir, ignore_errors=True)
os.environ['DESTDIR'] = str(dest_dir)
main(sys.argv)
Loading