Skip to content

Commit 4bb725c

Browse files
authored
Merge pull request github#15656 from github/criemen/ruby-bazel
Ruby: Start building the language pack using bazel.
2 parents 234623e + 1657b31 commit 4bb725c

File tree

11 files changed

+8524
-76
lines changed

11 files changed

+8524
-76
lines changed

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ javascript/ql/experimental/adaptivethreatmodeling/test/endpoint_large_scale/auto
7474

7575
# Auto-generated modeling for Python
7676
python/ql/lib/semmle/python/frameworks/data/internal/subclass-capture/*.yml linguist-generated=true
77+
78+
# auto-generated bazel lock file
79+
ruby/extractor/cargo-bazel-lock.json linguist-generated=true
80+
ruby/extractor/cargo-bazel-lock.json -merge

.github/workflows/ruby-build.yml

Lines changed: 8 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ jobs:
5151
run: |
5252
brew install gnu-tar
5353
echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH
54-
- name: Install cargo-cross
55-
if: runner.os == 'Linux'
56-
run: cargo install cross --version 0.2.5
54+
- name: Prepare Windows
55+
if: runner.os == 'Windows'
56+
shell: powershell
57+
run: |
58+
git config --global core.longpaths true
5759
- uses: ./.github/actions/os-version
5860
id: os_version
5961
- name: Cache entire extractor
@@ -82,16 +84,8 @@ jobs:
8284
- name: Run tests
8385
if: steps.cache-extractor.outputs.cache-hit != 'true'
8486
run: cd extractor && cargo test --verbose
85-
# On linux, build the extractor via cross in a centos7 container.
86-
# This ensures we don't depend on glibc > 2.17.
87-
- name: Release build (linux)
88-
if: steps.cache-extractor.outputs.cache-hit != 'true' && runner.os == 'Linux'
89-
run: |
90-
cd extractor
91-
cross build --release
92-
mv target/x86_64-unknown-linux-gnu/release/codeql-extractor-ruby target/release/
93-
- name: Release build (windows and macos)
94-
if: steps.cache-extractor.outputs.cache-hit != 'true' && runner.os != 'Linux'
87+
- name: Release build
88+
if: steps.cache-extractor.outputs.cache-hit != 'true'
9589
run: cd extractor && cargo build --release
9690
- name: Generate dbscheme
9791
if: ${{ matrix.os == 'ubuntu-latest' && steps.cache-extractor.outputs.cache-hit != 'true'}}
@@ -123,7 +117,7 @@ jobs:
123117
- name: Cache compilation cache
124118
id: query-cache
125119
uses: ./.github/actions/cache-query-compilation
126-
with:
120+
with:
127121
key: ruby-build
128122
- name: Build Query Pack
129123
run: |
@@ -235,54 +229,3 @@ jobs:
235229
shell: bash
236230
run: |
237231
codeql database analyze --search-path "${{ runner.temp }}/ruby-bundle" --format=sarifv2.1.0 --output=out.sarif ../database ruby-code-scanning.qls
238-
239-
# This is a copy of the 'test' job that runs in a centos7 container.
240-
# This tests that the extractor works correctly on systems with an old glibc.
241-
test-centos7:
242-
defaults:
243-
run:
244-
working-directory: ${{ github.workspace }}
245-
strategy:
246-
fail-fast: false
247-
runs-on: ubuntu-latest
248-
container:
249-
image: centos:centos7
250-
env:
251-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
252-
needs: [package]
253-
steps:
254-
- name: Install gh cli
255-
run: |
256-
yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
257-
# fetch-codeql requires unzip and jq
258-
# jq is available in epel-release (https://docs.fedoraproject.org/en-US/epel/)
259-
yum install -y gh unzip epel-release
260-
yum install -y jq
261-
- uses: actions/checkout@v3
262-
- name: Fetch CodeQL
263-
uses: ./.github/actions/fetch-codeql
264-
265-
# Due to a bug in Actions, we can't use runner.temp in the run blocks here.
266-
# https://github.com/actions/runner/issues/2185
267-
268-
- name: Download Ruby bundle
269-
uses: actions/download-artifact@v3
270-
with:
271-
name: codeql-ruby-bundle
272-
path: ${{ runner.temp }}
273-
- name: Unzip Ruby bundle
274-
shell: bash
275-
run: unzip -q -d "$RUNNER_TEMP"/ruby-bundle "$RUNNER_TEMP"/codeql-ruby-bundle.zip
276-
277-
- name: Run QL test
278-
shell: bash
279-
run: |
280-
codeql test run --search-path "$RUNNER_TEMP"/ruby-bundle --additional-packs "$RUNNER_TEMP"/ruby-bundle ruby/ql/test/library-tests/ast/constants/
281-
- name: Create database
282-
shell: bash
283-
run: |
284-
codeql database create --search-path "$RUNNER_TEMP"/ruby-bundle --language ruby --source-root ruby/ql/test/library-tests/ast/constants/ ../database
285-
- name: Analyze database
286-
shell: bash
287-
run: |
288-
codeql database analyze --search-path "$RUNNER_TEMP"/ruby-bundle --format=sarifv2.1.0 --output=out.sarif ../database ruby-code-scanning.qls

ruby/BUILD.bazel

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files")
2+
load("@semmle_code//:dist.bzl", "dist", "pack_zip")
3+
load("//:defs.bzl", "codeql_platform")
4+
5+
package(default_visibility = ["//visibility:public"])
6+
7+
alias(
8+
name = "dbscheme",
9+
actual = "//ruby/ql/lib:dbscheme",
10+
)
11+
12+
alias(
13+
name = "dbscheme-stats",
14+
actual = "//ruby/ql/lib:dbscheme-stats",
15+
)
16+
17+
pkg_files(
18+
name = "dbscheme-group",
19+
srcs = [
20+
":dbscheme",
21+
":dbscheme-stats",
22+
],
23+
strip_prefix = None,
24+
)
25+
26+
pkg_filegroup(
27+
name = "db-files",
28+
srcs = [
29+
":dbscheme-group",
30+
"//ruby/downgrades",
31+
],
32+
)
33+
34+
pkg_files(
35+
name = "codeql-extractor-yml",
36+
srcs = ["codeql-extractor.yml"],
37+
strip_prefix = None,
38+
)
39+
40+
dist(
41+
name = "extractor-generic",
42+
srcs = [
43+
":codeql-extractor-yml",
44+
":dbscheme-group",
45+
"//ruby/downgrades",
46+
"//ruby/tools",
47+
],
48+
prefix = "ruby",
49+
visibility = ["//visibility:public"],
50+
)
51+
52+
pack_zip(
53+
name = "extractor-arch",
54+
srcs = [
55+
"//ruby/extractor",
56+
],
57+
package_file_name = "extractor-" + codeql_platform + ".zip",
58+
prefix = "ruby/tools/" + codeql_platform,
59+
visibility = ["//visibility:public"],
60+
)

ruby/downgrades/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
2+
3+
pkg_files(
4+
name = "downgrades",
5+
srcs = glob(
6+
["**"],
7+
exclude = ["BUILD.bazel"],
8+
),
9+
prefix = "downgrades",
10+
strip_prefix = strip_prefix.from_pkg(),
11+
visibility = ["//ruby:__pkg__"],
12+
)

ruby/extractor/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("@ruby_deps//:defs.bzl", "aliases", "all_crate_deps")
2+
load("@semmle_code//:common.bzl", "codeql_rust_binary")
3+
4+
codeql_rust_binary(
5+
name = "extractor",
6+
srcs = glob(["src/*.rs"]),
7+
aliases = aliases(),
8+
proc_macro_deps = all_crate_deps(
9+
proc_macro = True,
10+
),
11+
visibility = ["//visibility:public"],
12+
deps = all_crate_deps(
13+
normal = True,
14+
),
15+
)

ruby/extractor/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ruby/extractor/Cargo.toml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ version = "0.1.0"
55
authors = ["GitHub"]
66
edition = "2018"
77

8-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9-
8+
# When changing/updating these, the `cargo-bazel-lock.json` file has to be regenerated.
9+
# Run `CARGO_BAZEL_REPIN=true CARGO_BAZEL_REPIN_ONLY=ruby_deps ./build --bazel sync --only=ruby_deps`
10+
# in the `semmle-code` repository to do so.
11+
# For more information, check out the documentation at
12+
# https://bazelbuild.github.io/rules_rust/crate_universe.html#repinning--updating-dependencies
13+
# In the future, the hope is to move this handling of the dependencies entirely into the `codeql` repository,
14+
# but that depends on `rules_rust` being fully compatible with bzlmod, which they aren't yet
15+
# (c.f. https://github.com/bazelbuild/rules_rust/issues/2452).
16+
# Warning: The process takes >5min on my M1 mac, so do wait for a while.
1017
[dependencies]
1118
tree-sitter = "0.20"
1219
tree-sitter-embedded-template = { git = "https://github.com/tree-sitter/tree-sitter-embedded-template.git", rev = "203f7bd3c1bbfbd98fc19add4b8fcb213c059205" }
@@ -18,4 +25,13 @@ rayon = "1.5.0"
1825
regex = "1.7.1"
1926
encoding = "0.2"
2027
lazy_static = "1.4.0"
21-
codeql-extractor = { path = "../../shared/tree-sitter-extractor" }
28+
# Ideally, we'd like to pull this in via a relative path.
29+
# However, our bazel/rust tooling chokes on this, c.f. https://github.com/bazelbuild/rules_rust/issues/1525
30+
# Therefore, to break that dependency, we depend on it via a git dependency instead.
31+
# We should change this back to a path dependency once this issue is fixed.
32+
# We can't depend on this without a rev/branch specification, as the rules_rust code assumes the default branch
33+
# is called `master`, and if we pull this in with `branch=main`, then `cargo` works (and pins this at th current git SHA
34+
# of lock-file update time, but `rules_rust` pins generates a bazel rule that unconditionally downloads `main`, which
35+
# breaks build hermeticity. So, rev-pinning it is.
36+
# See also https://github.com/bazelbuild/rules_rust/issues/2502.
37+
codeql-extractor = { git = "https://github.com/github/codeql.git", rev = "514a92d5bd1e24e4b7367d64430762ffd1ffbe7f" }

ruby/extractor/Cross.toml

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)