Compare commits

...

5 Commits

Author SHA1 Message Date
Cornelius Riemenschneider
8fba481a04 shorter paths 2024-02-26 00:32:46 +01:00
Cornelius Riemenschneider
9433201b58 add bzlmod 2024-02-25 23:51:00 +01:00
Cornelius Riemenschneider
c097397c32 Address review, start accomodating bzlmod. 2024-02-22 22:02:14 +01:00
Cornelius Riemenschneider
3d5d1bc59e Fix windows CI build.
As we're now checking out the `codeql` repo in a sub-path,
we need to enable long paths on Windows.
2024-02-22 21:25:59 +01:00
Cornelius Riemenschneider
007fc89543 Ruby: Start building the language pack using bazel.
This PR introduces a bazel and `rules_rust`-based build system
for the ruby extractor and language pack.
This replacese the existing, `cargo` and `cross`-based build system.

For local development, nothing changes, and the existing `cargo`-based
build still keeps working as-is.

We no longer need to use `cross` to compile our Linux binaries,
as we now can link against our hermetic C++ toolchain, which ships
with an old enough glibc, so that we don't run into symbol version issues
when deploying the binaries to older systems.
Besides the one change in dependency (explained in detail in `Cargo.toml`
and in https://github.com/github/codeql/pull/15595), nothing ought to
change in how we build the extractor.
2024-02-22 21:25:59 +01:00
11 changed files with 149 additions and 76 deletions

4
.gitattributes vendored
View File

@@ -74,3 +74,7 @@ javascript/ql/experimental/adaptivethreatmodeling/test/endpoint_large_scale/auto
# Auto-generated modeling for Python
python/ql/lib/semmle/python/frameworks/data/internal/subclass-capture/*.yml linguist-generated=true
# auto-generated bazel lock file
ruby/extractor/cargo-bazel-lock.json linguist-generated=true
ruby/extractor/cargo-bazel-lock.json -merge

View File

@@ -51,9 +51,11 @@ jobs:
run: |
brew install gnu-tar
echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH
- name: Install cargo-cross
if: runner.os == 'Linux'
run: cargo install cross --version 0.2.5
- name: Prepare Windows
if: runner.os == 'Windows'
shell: powershell
run: |
git config --global core.longpaths true
- uses: ./.github/actions/os-version
id: os_version
- name: Cache entire extractor
@@ -82,16 +84,8 @@ jobs:
- name: Run tests
if: steps.cache-extractor.outputs.cache-hit != 'true'
run: cd extractor && cargo test --verbose
# On linux, build the extractor via cross in a centos7 container.
# This ensures we don't depend on glibc > 2.17.
- name: Release build (linux)
if: steps.cache-extractor.outputs.cache-hit != 'true' && runner.os == 'Linux'
run: |
cd extractor
cross build --release
mv target/x86_64-unknown-linux-gnu/release/codeql-extractor-ruby target/release/
- name: Release build (windows and macos)
if: steps.cache-extractor.outputs.cache-hit != 'true' && runner.os != 'Linux'
- name: Release build
if: steps.cache-extractor.outputs.cache-hit != 'true'
run: cd extractor && cargo build --release
- name: Generate dbscheme
if: ${{ matrix.os == 'ubuntu-latest' && steps.cache-extractor.outputs.cache-hit != 'true'}}
@@ -123,7 +117,7 @@ jobs:
- name: Cache compilation cache
id: query-cache
uses: ./.github/actions/cache-query-compilation
with:
with:
key: ruby-build
- name: Build Query Pack
run: |
@@ -235,54 +229,3 @@ jobs:
shell: bash
run: |
codeql database analyze --search-path "${{ runner.temp }}/ruby-bundle" --format=sarifv2.1.0 --output=out.sarif ../database ruby-code-scanning.qls
# This is a copy of the 'test' job that runs in a centos7 container.
# This tests that the extractor works correctly on systems with an old glibc.
test-centos7:
defaults:
run:
working-directory: ${{ github.workspace }}
strategy:
fail-fast: false
runs-on: ubuntu-latest
container:
image: centos:centos7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
needs: [package]
steps:
- name: Install gh cli
run: |
yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
# fetch-codeql requires unzip and jq
# jq is available in epel-release (https://docs.fedoraproject.org/en-US/epel/)
yum install -y gh unzip epel-release
yum install -y jq
- uses: actions/checkout@v3
- name: Fetch CodeQL
uses: ./.github/actions/fetch-codeql
# Due to a bug in Actions, we can't use runner.temp in the run blocks here.
# https://github.com/actions/runner/issues/2185
- name: Download Ruby bundle
uses: actions/download-artifact@v3
with:
name: codeql-ruby-bundle
path: ${{ runner.temp }}
- name: Unzip Ruby bundle
shell: bash
run: unzip -q -d "$RUNNER_TEMP"/ruby-bundle "$RUNNER_TEMP"/codeql-ruby-bundle.zip
- name: Run QL test
shell: bash
run: |
codeql test run --search-path "$RUNNER_TEMP"/ruby-bundle --additional-packs "$RUNNER_TEMP"/ruby-bundle ruby/ql/test/library-tests/ast/constants/
- name: Create database
shell: bash
run: |
codeql database create --search-path "$RUNNER_TEMP"/ruby-bundle --language ruby --source-root ruby/ql/test/library-tests/ast/constants/ ../database
- name: Analyze database
shell: bash
run: |
codeql database analyze --search-path "$RUNNER_TEMP"/ruby-bundle --format=sarifv2.1.0 --output=out.sarif ../database ruby-code-scanning.qls

View File

@@ -21,6 +21,7 @@ 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 = "rules_rust", version = "0.39.0")
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
@@ -51,3 +52,18 @@ use_repo(node, "nodejs", "nodejs_toolchains")
register_toolchains(
"@nodejs_toolchains//:all",
)
crate = use_extension(
"@rules_rust//crate_universe:extension.bzl",
"crate",
)
crate.from_cargo(
name = "r", # short name due to long path issues on windows
cargo_lockfile = "//ruby/extractor:Cargo.lock",
manifests = [
"//ruby/extractor:Cargo.toml",
],
)
use_repo(crate, "r")

60
ruby/BUILD.bazel Normal file
View File

@@ -0,0 +1,60 @@
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files")
load("@semmle_code//:dist.bzl", "dist", "pack_zip")
load("//:defs.bzl", "codeql_platform")
package(default_visibility = ["//visibility:public"])
alias(
name = "dbscheme",
actual = "//ruby/ql/lib:dbscheme",
)
alias(
name = "dbscheme-stats",
actual = "//ruby/ql/lib:dbscheme-stats",
)
pkg_files(
name = "dbscheme-group",
srcs = [
":dbscheme",
":dbscheme-stats",
],
strip_prefix = None,
)
pkg_filegroup(
name = "db-files",
srcs = [
":dbscheme-group",
"//ruby/downgrades",
],
)
pkg_files(
name = "codeql-extractor-yml",
srcs = ["codeql-extractor.yml"],
strip_prefix = None,
)
dist(
name = "extractor-generic",
srcs = [
":codeql-extractor-yml",
":dbscheme-group",
"//ruby/downgrades",
"//ruby/tools",
],
prefix = "ruby",
visibility = ["//visibility:public"],
)
pack_zip(
name = "extractor-arch",
srcs = [
"//ruby/extractor",
],
package_file_name = "extractor-" + codeql_platform + ".zip",
prefix = "ruby/tools/" + codeql_platform,
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,12 @@
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
pkg_files(
name = "downgrades",
srcs = glob(
["**"],
exclude = ["BUILD.bazel"],
),
prefix = "downgrades",
strip_prefix = strip_prefix.from_pkg(),
visibility = ["//ruby:__pkg__"],
)

View File

@@ -0,0 +1,15 @@
load("@r//:defs.bzl", "aliases", "all_crate_deps")
load("@semmle_code//:common.bzl", "codeql_rust_binary")
codeql_rust_binary(
name = "extractor",
srcs = glob(["src/*.rs"]),
aliases = aliases(),
proc_macro_deps = all_crate_deps(
proc_macro = True,
),
visibility = ["//visibility:public"],
deps = all_crate_deps(
normal = True,
),
)

Binary file not shown.

View File

@@ -5,8 +5,6 @@ version = "0.1.0"
authors = ["GitHub"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tree-sitter = "0.20"
tree-sitter-embedded-template = { git = "https://github.com/tree-sitter/tree-sitter-embedded-template.git", rev = "203f7bd3c1bbfbd98fc19add4b8fcb213c059205" }
@@ -18,4 +16,13 @@ rayon = "1.5.0"
regex = "1.7.1"
encoding = "0.2"
lazy_static = "1.4.0"
codeql-extractor = { path = "../../shared/tree-sitter-extractor" }
# Ideally, we'd like to pull this in via a relative path.
# However, our bazel/rust tooling chokes on this, c.f. https://github.com/bazelbuild/rules_rust/issues/1525
# Therefore, to break that dependency, we depend on it via a git dependency instead.
# We should change this back to a path dependency once this issue is fixed.
# We can't depend on this without a rev/branch specification, as the rules_rust code assumes the default branch
# is called `master`, and if we pull this in with `branch=main`, then `cargo` works (and pins this at th current git SHA
# of lock-file update time, but `rules_rust` pins generates a bazel rule that unconditionally downloads `main`, which
# breaks build hermeticity. So, rev-pinning it is.
# See also https://github.com/bazelbuild/rules_rust/issues/2502.
codeql-extractor = { git = "https://github.com/github/codeql.git", rev = "514a92d5bd1e24e4b7367d64430762ffd1ffbe7f" }

View File

@@ -1,8 +0,0 @@
[target.x86_64-unknown-linux-gnu]
image = "centos/devtoolset-7-toolchain-centos7"
[build.env]
# Provide the path to the shared extractor
# Cross mounts this directory as a volume, so builds inside the docker container
# can see it.
volumes = ["__CODEQL-EXTRACTOR=../../shared/tree-sitter-extractor"]

13
ruby/ql/lib/BUILD.bazel Normal file
View File

@@ -0,0 +1,13 @@
load("@rules_pkg//:mappings.bzl", "pkg_files")
package(default_visibility = ["//ruby:__pkg__"])
pkg_files(
name = "dbscheme",
srcs = ["ruby.dbscheme"],
)
pkg_files(
name = "dbscheme-stats",
srcs = ["ruby.dbscheme.stats"],
)

11
ruby/tools/BUILD.bazel Normal file
View File

@@ -0,0 +1,11 @@
load("@semmle_code//:dist.bzl", "pack_zip")
pack_zip(
name = "tools",
srcs = glob(["**/*"]),
excludes = [
"BUILD.bazel",
],
prefix = "tools",
visibility = ["//visibility:public"],
)