mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Rust: bazel packaging
This commit is contained in:
14
MODULE.bazel
14
MODULE.bazel
@@ -63,6 +63,20 @@ r.from_cargo(
|
|||||||
)
|
)
|
||||||
use_repo(r, ruby_deps = "rd")
|
use_repo(r, ruby_deps = "rd")
|
||||||
|
|
||||||
|
rsp = use_extension(
|
||||||
|
"@rules_rust//crate_universe:extension.bzl",
|
||||||
|
"crate",
|
||||||
|
isolate = True,
|
||||||
|
)
|
||||||
|
rsp.from_cargo(
|
||||||
|
name = "rs_deps",
|
||||||
|
cargo_lockfile = "//rust/extractor:Cargo.lock",
|
||||||
|
manifests = [
|
||||||
|
"//rust/extractor:Cargo.toml",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
use_repo(rsp, rust_deps = "rs_deps")
|
||||||
|
|
||||||
dotnet = use_extension("@rules_dotnet//dotnet:extensions.bzl", "dotnet")
|
dotnet = use_extension("@rules_dotnet//dotnet:extensions.bzl", "dotnet")
|
||||||
dotnet.toolchain(dotnet_version = "8.0.101")
|
dotnet.toolchain(dotnet_version = "8.0.101")
|
||||||
use_repo(dotnet, "dotnet_toolchains")
|
use_repo(dotnet, "dotnet_toolchains")
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ def _get_type(t: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _get_field(cls: schema.Class, p: schema.Property) -> rust.Field:
|
def _get_field(cls: schema.Class, p: schema.Property) -> rust.Field:
|
||||||
table_name = None
|
table_name = inflection.tableize(cls.name)
|
||||||
if not p.is_single:
|
if not p.is_single:
|
||||||
table_name = f"{cls.name}_{p.name}"
|
table_name = f"{cls.name}_{p.name}"
|
||||||
if p.is_predicate:
|
if p.is_predicate:
|
||||||
@@ -47,11 +47,12 @@ def _get_field(cls: schema.Class, p: schema.Property) -> rust.Field:
|
|||||||
|
|
||||||
|
|
||||||
def _get_properties(
|
def _get_properties(
|
||||||
cls: schema.Class, lookup: dict[str, schema.Class]
|
cls: schema.Class, lookup: dict[str, schema.Class],
|
||||||
) -> typing.Iterable[schema.Property]:
|
) -> typing.Iterable[tuple[schema.Class, schema.Property]]:
|
||||||
for b in cls.bases:
|
for b in cls.bases:
|
||||||
yield from _get_properties(lookup[b], lookup)
|
yield from _get_properties(lookup[b], lookup)
|
||||||
yield from cls.properties
|
for p in cls.properties:
|
||||||
|
yield cls, p
|
||||||
|
|
||||||
|
|
||||||
class Processor:
|
class Processor:
|
||||||
@@ -63,8 +64,8 @@ class Processor:
|
|||||||
return rust.Class(
|
return rust.Class(
|
||||||
name=name,
|
name=name,
|
||||||
fields=[
|
fields=[
|
||||||
_get_field(cls, p)
|
_get_field(c, p)
|
||||||
for p in _get_properties(cls, self._classmap)
|
for c, p in _get_properties(cls, self._classmap)
|
||||||
if "rust_skip" not in p.pragmas and not p.synth
|
if "rust_skip" not in p.pragmas and not p.synth
|
||||||
],
|
],
|
||||||
table_name=inflection.tableize(cls.name),
|
table_name=inflection.tableize(cls.name),
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ def get_field_override(field: str):
|
|||||||
class Field:
|
class Field:
|
||||||
field_name: str
|
field_name: str
|
||||||
base_type: str
|
base_type: str
|
||||||
table_name: str = None
|
table_name: str
|
||||||
is_optional: bool = False
|
is_optional: bool = False
|
||||||
is_repeated: bool = False
|
is_repeated: bool = False
|
||||||
is_unordered: bool = False
|
is_unordered: bool = False
|
||||||
@@ -121,8 +121,12 @@ class Class:
|
|||||||
fields: list[Field] = dataclasses.field(default_factory=list)
|
fields: list[Field] = dataclasses.field(default_factory=list)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def single_fields(self):
|
def single_field_entries(self):
|
||||||
return [f for f in self.fields if f.is_single]
|
ret = {self.table_name: []}
|
||||||
|
for f in self.fields:
|
||||||
|
if f.is_single:
|
||||||
|
ret.setdefault(f.table_name, []).append(f)
|
||||||
|
return [{"table_name": k, "fields": v} for k, v in ret.items()]
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ impl TrapEntry for {{name}} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn emit<W: Write>(self, id: TrapLabel, out: &mut W) -> std::io::Result<()> {
|
fn emit<W: Write>(self, id: TrapLabel, out: &mut W) -> std::io::Result<()> {
|
||||||
write!(out, "{{table_name}}({id}{{#single_fields}}, {}{{/single_fields}})\n"{{#single_fields}}, {{#emitter}}self.{{field_name}}{{/emitter}}{{/single_fields}})?;
|
{{#single_field_entries}}
|
||||||
|
write!(out, "{{table_name}}({id}{{#fields}}, {}{{/fields}})\n"{{#fields}}, {{#emitter}}self.{{field_name}}{{/emitter}}{{/fields}})?;
|
||||||
|
{{/single_field_entries}}
|
||||||
{{#fields}}
|
{{#fields}}
|
||||||
{{#is_predicate}}
|
{{#is_predicate}}
|
||||||
if self.{{field_name}} {
|
if self.{{field_name}} {
|
||||||
|
|||||||
5
rust/.idea/.gitignore
generated
vendored
Normal file
5
rust/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
6
rust/.idea/misc.xml
generated
Normal file
6
rust/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="MarkdownSettingsMigration">
|
||||||
|
<option name="stateVersion" value="1" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
8
rust/.idea/modules.xml
generated
Normal file
8
rust/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/rust.iml" filepath="$PROJECT_DIR$/.idea/rust.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
13
rust/.idea/rust.iml
generated
Normal file
13
rust/.idea/rust.iml
generated
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="EMPTY_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/extractor/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/extractor/target" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
rust/.idea/vcs.xml
generated
Normal file
6
rust/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -1,4 +1,55 @@
|
|||||||
exports_files([
|
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup")
|
||||||
"codegen.conf",
|
load(
|
||||||
"schema.py",
|
"//misc/bazel:pkg.bzl",
|
||||||
])
|
"codeql_pack",
|
||||||
|
"codeql_pkg_files",
|
||||||
|
)
|
||||||
|
|
||||||
|
package(default_visibility = ["//rust:__subpackages__"])
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "schema",
|
||||||
|
srcs = ["schema.py"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "schema-includes",
|
||||||
|
srcs = glob(["*.dbscheme"]),
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "codegen-conf",
|
||||||
|
srcs = ["codegen.conf"],
|
||||||
|
)
|
||||||
|
|
||||||
|
codeql_pkg_files(
|
||||||
|
name = "tools-arch",
|
||||||
|
exes = ["//rust/extractor"],
|
||||||
|
prefix = "{CODEQL_PLATFORM}",
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_filegroup(
|
||||||
|
name = "tools",
|
||||||
|
srcs = [
|
||||||
|
":tools-arch",
|
||||||
|
"//rust/tools",
|
||||||
|
],
|
||||||
|
prefix = "tools",
|
||||||
|
)
|
||||||
|
|
||||||
|
codeql_pkg_files(
|
||||||
|
name = "root-files",
|
||||||
|
srcs = [
|
||||||
|
"codeql-extractor.yml",
|
||||||
|
"ql/lib/rust.dbscheme",
|
||||||
|
"ql/lib/rust.dbscheme.stats",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
codeql_pack(
|
||||||
|
name = "rust",
|
||||||
|
srcs = [
|
||||||
|
":root-files",
|
||||||
|
":tools",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|||||||
@@ -4,6 +4,6 @@
|
|||||||
--ql-output=ql/lib/codeql/rust/generated
|
--ql-output=ql/lib/codeql/rust/generated
|
||||||
--ql-stub-output=ql/lib/codeql/rust/elements
|
--ql-stub-output=ql/lib/codeql/rust/elements
|
||||||
--ql-test-output=ql/test/extractor-tests/generated
|
--ql-test-output=ql/test/extractor-tests/generated
|
||||||
--rust-output=src/generated
|
--rust-output=extractor/src/generated
|
||||||
--generated-registry=.generated.list
|
--generated-registry=.generated.list
|
||||||
--script-name=codegen
|
--script-name=codegen
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ native_binary(
|
|||||||
src = "//misc/codegen",
|
src = "//misc/codegen",
|
||||||
out = "codegen",
|
out = "codegen",
|
||||||
args = [
|
args = [
|
||||||
"--configuration-file=$(location //rust:codegen.conf)",
|
"--configuration-file=$(location //rust:codegen-conf)",
|
||||||
],
|
],
|
||||||
data = [
|
data = [
|
||||||
"//rust:codegen.conf",
|
"//rust:codegen-conf",
|
||||||
"//rust:schema.py",
|
"//rust:schema",
|
||||||
],
|
],
|
||||||
visibility = ["//rust:__subpackages__"],
|
visibility = ["//rust:__subpackages__"],
|
||||||
)
|
)
|
||||||
|
|||||||
15
rust/codeql-extractor.yml
Normal file
15
rust/codeql-extractor.yml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
name: "rust"
|
||||||
|
display_name: "Rust"
|
||||||
|
version: 0.1.0
|
||||||
|
column_kind: "utf8"
|
||||||
|
build_modes:
|
||||||
|
- none
|
||||||
|
github_api_languages:
|
||||||
|
- Rust
|
||||||
|
scc_languages:
|
||||||
|
- Rust
|
||||||
|
file_types:
|
||||||
|
- name: rust
|
||||||
|
display_name: Rust files
|
||||||
|
extensions:
|
||||||
|
- .rs
|
||||||
15
rust/extractor/BUILD.bazel
Normal file
15
rust/extractor/BUILD.bazel
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
load("@rust_deps//:defs.bzl", "aliases", "all_crate_deps")
|
||||||
|
load("//misc/bazel:rust.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 = ["//rust:__subpackages__"],
|
||||||
|
deps = all_crate_deps(
|
||||||
|
normal = True,
|
||||||
|
),
|
||||||
|
)
|
||||||
3
rust/Cargo.lock → rust/extractor/Cargo.lock
generated
3
rust/Cargo.lock → rust/extractor/Cargo.lock
generated
@@ -1566,8 +1566,7 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc_apfloat"
|
name = "rustc_apfloat"
|
||||||
version = "0.2.1+llvm-462a31f5a5ab"
|
version = "0.2.1+llvm-462a31f5a5ab"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/redsun82/rustc_apfloat.git?rev=096d585100636bc2e9f09d7eefec38c5b334d47b#096d585100636bc2e9f09d7eefec38c5b334d47b"
|
||||||
checksum = "886d94c63c812a8037c4faca2607453a0fa4cf82f734665266876b022244543f"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
@@ -21,3 +21,8 @@ serde = "1.0.209"
|
|||||||
serde_with = "3.9.0"
|
serde_with = "3.9.0"
|
||||||
stderrlog = "0.6.0"
|
stderrlog = "0.6.0"
|
||||||
triomphe = "0.1.13"
|
triomphe = "0.1.13"
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
# patch for build script bug preventing bazel build
|
||||||
|
# see https://github.com/rust-lang/rustc_apfloat/pull/17
|
||||||
|
rustc_apfloat = { git = "https://github.com/redsun82/rustc_apfloat.git", rev = "096d585100636bc2e9f09d7eefec38c5b334d47b" }
|
||||||
@@ -19,7 +19,7 @@ impl Archiver {
|
|||||||
let mut dest = self.root.clone();
|
let mut dest = self.root.clone();
|
||||||
dest.push(path::key(source));
|
dest.push(path::key(source));
|
||||||
let parent = dest.parent().unwrap();
|
let parent = dest.parent().unwrap();
|
||||||
if fs::exists(&dest)? {
|
if fs::metadata(&dest).is_ok() {
|
||||||
return Ok(())
|
return Ok(())
|
||||||
}
|
}
|
||||||
fs::create_dir_all(parent)?;
|
fs::create_dir_all(parent)?;
|
||||||
@@ -15,7 +15,8 @@ impl TrapEntry for DbFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn emit<W: Write>(self, id: TrapLabel, out: &mut W) -> std::io::Result<()> {
|
fn emit<W: Write>(self, id: TrapLabel, out: &mut W) -> std::io::Result<()> {
|
||||||
write!(out, "db_files({id}, {})\n", quoted(&self.name))?;
|
write!(out, "db_files({id})\n")?;
|
||||||
|
write!(out, "files({id}, {})\n", quoted(&self.name))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,7 +37,8 @@ impl TrapEntry for DbLocation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn emit<W: Write>(self, id: TrapLabel, out: &mut W) -> std::io::Result<()> {
|
fn emit<W: Write>(self, id: TrapLabel, out: &mut W) -> std::io::Result<()> {
|
||||||
write!(out, "db_locations({id}, {}, {}, {}, {}, {})\n", self.file, self.start_line, self.start_column, self.end_line, self.end_column)?;
|
write!(out, "db_locations({id})\n")?;
|
||||||
|
write!(out, "locations({id}, {}, {}, {}, {}, {})\n", self.file, self.start_line, self.start_column, self.end_line, self.end_column)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,7 +58,7 @@ impl TrapEntry for Function {
|
|||||||
fn emit<W: Write>(self, id: TrapLabel, out: &mut W) -> std::io::Result<()> {
|
fn emit<W: Write>(self, id: TrapLabel, out: &mut W) -> std::io::Result<()> {
|
||||||
write!(out, "functions({id}, {})\n", quoted(&self.name))?;
|
write!(out, "functions({id}, {})\n", quoted(&self.name))?;
|
||||||
if let Some(ref v) = &self.location {
|
if let Some(ref v) = &self.location {
|
||||||
write!(out, "function_locations({id}, {})\n", v)?;
|
write!(out, "locatable_locations({id}, {})\n", v)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -77,7 +79,7 @@ impl TrapEntry for Module {
|
|||||||
fn emit<W: Write>(self, id: TrapLabel, out: &mut W) -> std::io::Result<()> {
|
fn emit<W: Write>(self, id: TrapLabel, out: &mut W) -> std::io::Result<()> {
|
||||||
write!(out, "modules({id})\n")?;
|
write!(out, "modules({id})\n")?;
|
||||||
if let Some(ref v) = &self.location {
|
if let Some(ref v) = &self.location {
|
||||||
write!(out, "module_locations({id}, {})\n", v)?;
|
write!(out, "locatable_locations({id}, {})\n", v)?;
|
||||||
}
|
}
|
||||||
for (i, &ref v) in self.declarations.iter().enumerate() {
|
for (i, &ref v) in self.declarations.iter().enumerate() {
|
||||||
write!(out, "module_declarations({id}, {}, {})\n", i, v)?;
|
write!(out, "module_declarations({id}, {}, {})\n", i, v)?;
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
#![feature(path_add_extension)]
|
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{PathBuf, Path};
|
use std::path::{PathBuf, Path};
|
||||||
use ra_ap_project_model::CargoConfig;
|
use ra_ap_project_model::CargoConfig;
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use std::ffi::OsString;
|
||||||
use std::fmt::{Debug, Display, Formatter};
|
use std::fmt::{Debug, Display, Formatter};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
@@ -158,7 +159,11 @@ impl TrapFileProvider {
|
|||||||
pub fn create(&self, category: &str, key: &Path) -> std::io::Result<TrapFile> {
|
pub fn create(&self, category: &str, key: &Path) -> std::io::Result<TrapFile> {
|
||||||
let mut path = PathBuf::from(category);
|
let mut path = PathBuf::from(category);
|
||||||
path.push(path::key(key));
|
path.push(path::key(key));
|
||||||
path.add_extension("trap");
|
path.set_extension(path.extension().map(|e| {
|
||||||
|
let mut o : OsString = e.to_owned();
|
||||||
|
o.push(".trap");
|
||||||
|
o
|
||||||
|
}).unwrap_or("trap".into()));
|
||||||
let trap_name = String::from(path.to_string_lossy());
|
let trap_name = String::from(path.to_string_lossy());
|
||||||
debug!("creating trap file {}", trap_name);
|
debug!("creating trap file {}", trap_name);
|
||||||
path = self.trap_dir.join(path);
|
path = self.trap_dir.join(path);
|
||||||
4
rust/ql/lib/rust.dbscheme.stats
Normal file
4
rust/ql/lib/rust.dbscheme.stats
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<dbstats>
|
||||||
|
<typesizes />
|
||||||
|
<stats />
|
||||||
|
</dbstats>
|
||||||
9
rust/tools/BUILD.bazel
Normal file
9
rust/tools/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
load("//misc/bazel:pkg.bzl", "codeql_pkg_files")
|
||||||
|
|
||||||
|
codeql_pkg_files(
|
||||||
|
name = "tools",
|
||||||
|
exes = [
|
||||||
|
"index.sh",
|
||||||
|
],
|
||||||
|
visibility = ["//rust:__pkg__"],
|
||||||
|
)
|
||||||
17
rust/tools/index.sh
Executable file
17
rust/tools/index.sh
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# TODO move this to rust code
|
||||||
|
|
||||||
|
inputs=($(find -name Cargo.toml))
|
||||||
|
|
||||||
|
if [ "${#inputs}" -eq 0 ]; then
|
||||||
|
inputs=($(find -name rust-project.json))
|
||||||
|
if [ "${#inputs}" -eq 0 ]; then
|
||||||
|
inputs=($(find -name '*.rs'))
|
||||||
|
if [ "${#inputs}" -eq 0 ]; then
|
||||||
|
echo "no source files found" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec "$CODEQL_EXTRACTOR_RUST_ROOT/tools/$CODEQL_PLATFORM/extractor" "${inputs[@]}"
|
||||||
Reference in New Issue
Block a user