Skip to content

Commit 2c4a216

Browse files
authored
Merge pull request #16616 from github/redsun82/fix-pkg
Reinstate bazel packaging library with a backward compatibility fix
2 parents 8509bca + 655f079 commit 2c4a216

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1962
-173
lines changed

.bazelrc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ common --override_module=semmle_code=%workspace%/misc/bazel/semmle_code_stub
1010

1111
build --repo_env=CC=clang --repo_env=CXX=clang++
1212

13-
build:linux --cxxopt=-std=c++20
13+
build:linux --cxxopt=-std=c++20 --host_cxxopt=-std=c++20
1414
# we currently cannot built the swift extractor for ARM
15-
build:macos --cxxopt=-std=c++20 --copt=-arch --copt=x86_64 --linkopt=-arch --linkopt=x86_64
16-
build:windows --cxxopt=/std:c++20 --cxxopt=/Zc:preprocessor
15+
build:macos --cxxopt=-std=c++20 --host_cxxopt=-std=c++20 --copt=-arch --copt=x86_64 --linkopt=-arch --linkopt=x86_64
16+
build:windows --cxxopt=/std:c++20 --cxxopt=/Zc:preprocessor --host_cxxopt=/std:c++20 --host_cxxopt=/Zc:preprocessor
1717

1818
# this requires developer mode, but is required to have pack installer functioning
1919
startup --windows_enable_symlinks
2020
common --enable_runfiles
2121

22+
# with the above, we can avoid building python zips which is the default on windows as that's expensive
23+
build --nobuild_python_zip
24+
2225
common --registry=file:///%workspace%/misc/bazel/registry
2326
common --registry=https://bcr.bazel.build
2427

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,9 @@ csharp/paket.lock linguist-generated=true
8080
csharp/.paket/Paket.Restore.targets linguist-generated=true eol=crlf
8181
csharp/paket.main.bzl linguist-generated=true
8282
csharp/paket.main_extension.bzl linguist-generated=true
83+
84+
# ripunzip tool
85+
/misc/bazel/internal/ripunzip/ripunzip-* filter=lfs diff=lfs merge=lfs -text
86+
87+
# swift prebuilt resources
88+
/swift/third_party/resource-dir/*.zip filter=lfs diff=lfs merge=lfs -text

.github/workflows/zipmerge-test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "Test zipmerge code"
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "misc/bazel/internal/zipmerge/**"
7+
- "MODULE.bazel"
8+
- ".bazelrc*"
9+
branches:
10+
- main
11+
- "rc/*"
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
test:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- run: |
23+
bazel test //misc/bazel/internal/zipmerge:test --test_output=all

MODULE.bazel

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json")
2424
bazel_dep(name = "fmt", version = "10.0.0")
2525
bazel_dep(name = "gazelle", version = "0.36.0")
2626
bazel_dep(name = "rules_dotnet", version = "0.15.1")
27+
bazel_dep(name = "googletest", version = "1.14.0.bcr.1")
2728

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

@@ -67,6 +68,36 @@ use_repo(node, "nodejs", "nodejs_toolchains")
6768
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
6869
go_sdk.download(version = "1.22.2")
6970

71+
lfs_files = use_repo_rule("//misc/bazel:lfs.bzl", "lfs_files")
72+
73+
lfs_files(
74+
name = "ripunzip-linux",
75+
srcs = ["//misc/bazel/internal/ripunzip:ripunzip-linux"],
76+
executable = True,
77+
)
78+
79+
lfs_files(
80+
name = "ripunzip-windows",
81+
srcs = ["//misc/bazel/internal/ripunzip:ripunzip-windows.exe"],
82+
executable = True,
83+
)
84+
85+
lfs_files(
86+
name = "ripunzip-macos",
87+
srcs = ["//misc/bazel/internal/ripunzip:ripunzip-macos"],
88+
executable = True,
89+
)
90+
91+
lfs_files(
92+
name = "swift-resource-dir-linux",
93+
srcs = ["//swift/third_party/resource-dir:resource-dir-linux.zip"],
94+
)
95+
96+
lfs_files(
97+
name = "swift-resource-dir-macos",
98+
srcs = ["//swift/third_party/resource-dir:resource-dir-macos.zip"],
99+
)
100+
70101
register_toolchains(
71102
"@nodejs_toolchains//:all",
72103
)

misc/bazel/internal/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports_files(["install.py"])

misc/bazel/internal/install.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Helper script for installing `codeql_pack` targets.
3+
4+
This mainly wraps around a `pkg_install` script from `rules_pkg` adding:
5+
* resolving destination directory with respect to a provided `--build-file`
6+
* clean-up of target destination directory before a reinstall
7+
* installing imported zip files using a provided `--ripunzip`
8+
"""
9+
10+
import argparse
11+
import pathlib
12+
import shutil
13+
import subprocess
14+
from python.runfiles import runfiles
15+
16+
runfiles = runfiles.Create()
17+
assert runfiles, "Installer should be run with `bazel run`"
18+
19+
parser = argparse.ArgumentParser(description=__doc__)
20+
parser.add_argument("--destdir", type=pathlib.Path, required=True,
21+
help="Desination directory, relative to `--build-file`")
22+
parser.add_argument("--pkg-install-script", required=True,
23+
help="The wrapped `pkg_install` installation script rlocation")
24+
parser.add_argument("--build-file", required=True,
25+
help="BUILD.bazel rlocation relative to which the installation should take place")
26+
parser.add_argument("--ripunzip",
27+
help="ripunzip executable rlocation. Must be provided if `--zip-manifest` is.")
28+
parser.add_argument("--zip-manifest",
29+
help="The rlocation of a file containing newline-separated `prefix:zip_file` entries")
30+
parser.add_argument("--cleanup", action=argparse.BooleanOptionalAction, default=True,
31+
help="Whether to wipe the destination directory before installing (true by default)")
32+
opts = parser.parse_args()
33+
if opts.zip_manifest and not opts.ripunzip:
34+
parser.error("Provide `--ripunzip` when specifying `--zip-manifest`")
35+
36+
build_file = runfiles.Rlocation(opts.build_file)
37+
script = runfiles.Rlocation(opts.pkg_install_script)
38+
destdir = pathlib.Path(build_file).resolve().parent / opts.destdir
39+
40+
if destdir.exists() and opts.cleanup:
41+
shutil.rmtree(destdir)
42+
43+
destdir.mkdir(parents=True, exist_ok=True)
44+
subprocess.run([script, "--destdir", destdir], check=True)
45+
46+
if opts.zip_manifest:
47+
ripunzip = runfiles.Rlocation(opts.ripunzip)
48+
zip_manifest = runfiles.Rlocation(opts.zip_manifest)
49+
with open(zip_manifest) as manifest:
50+
for line in manifest:
51+
prefix, _, zip = line.partition(":")
52+
assert zip, f"missing prefix for {prefix}, you should use prefix:zip format"
53+
dest = destdir / prefix
54+
dest.mkdir(parents=True, exist_ok=True)
55+
subprocess.run([ripunzip, "unzip-file", zip, "-d", dest], check=True)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
2+
3+
native_binary(
4+
name = "ripunzip",
5+
src = select({"@platforms//os:" + os: "@ripunzip-" + os for os in ("linux", "windows", "macos")}),
6+
out = "ripunzip.exe",
7+
visibility = ["//visibility:public"],
8+
)

0 commit comments

Comments
 (0)