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

Go: add bazel build #16317

merged 47 commits into from May 6, 2024

Conversation

redsun82
Copy link
Contributor

@redsun82 redsun82 commented Apr 24, 2024

The build files are mostly generated using gazelle. All file generation (vendor directory, BUILD files and dbscheme) can be triggered with bazel run //go:gen. The extractor pack can be built with bazel run //go:create-extractor-pack, which will put it in the same location that was used before (go/build/codeql-extractor-go).

The Makefile and .github workflows have not been updated, so CI will still use the old build here and in the internal repo. After the internal repo has been updated to use the new bazel definitions, we can clean up here.

@redsun82 redsun82 force-pushed the redsun82/go branch 2 times, most recently from 7165768 to 375660c Compare April 26, 2024 14:52
@redsun82 redsun82 added the depends on internal PR This PR should only be merged in sync with an internal Semmle PR label Apr 29, 2024
@redsun82 redsun82 requested review from mbg and criemen May 2, 2024 10:56
Copy link
Member

@mbg mbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all your work on this 🙇🏻

I have reviewed this from the perspective of the Go team, but a disclaimer that I am neither a Bazel nor a Python expert. So it should definitely be reviewed by someone who has more experience in those areas as well.

Mostly this looks good and it certainly seemed to work fine for me locally when running our tests. Other than some minor points and questions, the biggest question is probably about how we choose which version of Go to install and use in the GHA workflow -- see my detailed comments there.

MODULE.bazel Outdated
@@ -52,6 +54,9 @@ node.toolchain(
)
use_repo(node, "nodejs", "nodejs_toolchains")

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.22.2") # default
Copy link
Member

@mbg mbg May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I assume this now replaces the GO_VERSION environment variables in the workflows, so we should update the playbook accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, I will open a PR for that!

go/actions/test/action.yml Outdated Show resolved Hide resolved
go/actions/test/action.yml Outdated Show resolved Hide resolved
go/actions/test/action.yml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
go/gen.py Outdated Show resolved Hide resolved
go/gen.py Outdated Show resolved Hide resolved
go/gen.py Outdated Show resolved Hide resolved
go/codeql-tools/BUILD.bazel Show resolved Hide resolved
go/extractor/BUILD.bazel Show resolved Hide resolved
mbg
mbg previously approved these changes May 3, 2024
Copy link
Member

@mbg mbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks for all the improvements ✨

I just have one question, and a couple of minor, optional improvements.

go/codeql-tools/BUILD.bazel Show resolved Hide resolved
go/extractor/BUILD.bazel Outdated Show resolved Hide resolved
go/gen.py Outdated Show resolved Hide resolved
go/gen.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@criemen criemen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As usual, a bunch of questions/comments.

Mostly around how we set up the dist/language pack building, and the java rules.

Everything else LGTM, I'll take a look at the internal PR now.

MODULE.bazel Outdated Show resolved Hide resolved
go/BUILD.bazel Outdated Show resolved Hide resolved
go/BUILD.bazel Show resolved Hide resolved
go/BUILD.bazel Outdated Show resolved Hide resolved
go/codeql-tools/BUILD.bazel Show resolved Hide resolved
go/BUILD.bazel Outdated Show resolved Hide resolved
go/extractor/BUILD.bazel Outdated Show resolved Hide resolved
go/extractor/BUILD.bazel Show resolved Hide resolved
srcs = [":tokenizer-jar"],
prefix = "tools",
renames = {
":tokenizer-jar": "tokenizer.jar",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check that this JAR has all the class files? I'd expect you need to build a deploy jar here, as otherwise the tokenizer-deps library class files will not make it into tokenizer.jar. If our tests haven't uncovered this yet, we need to make sure this JAR is functional at all (see discussion above about JVM versions), and ideally add a test for this, so we don't accidentally break this functionality during bazel upgrades.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I checked that exactly the same files end up in the extractor pack. By the way, I'm no java expert so I don't know what this all entails, but the split between tokenizer-deps and tokenizer-jar is precisely intended to reproduce what was being done on the pack previously in the Makefile:

codeql/go/Makefile

Lines 101 to 106 in 880262d

tools/net/sourceforge/pmd/cpd/GoLanguage.class: extractor/net/sourceforge/pmd/cpd/GoLanguage.java
javac -cp extractor -d tools $<
rm tools/net/sourceforge/pmd/cpd/AbstractLanguage.class
rm tools/net/sourceforge/pmd/cpd/SourceCode.class
rm tools/net/sourceforge/pmd/cpd/TokenEntry.class
rm tools/net/sourceforge/pmd/cpd/Tokenizer.class

You can see we are actively rming the files in tokenizer-deps, so it seems we actually didn't want a deploy jar here? Maybe @mbg has more details here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I haven't dealt with this part of the codebase before. @smowton or @owen-mc may know more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oo okay, in that case this needs to be documented - the way it's currently written in the BUILD.bazel file it looks like a bug, not intended behavior. It is a correct reproduction of the behavior from the Makefile though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a comment then!

redsun82 and others added 4 commits May 3, 2024 14:52
Co-authored-by: Cornelius Riemenschneider <cornelius@github.com>
It turns out everything that is needed for the installer to work on
windows is enabling runfiles. This also requires symlinks to avoid
excessive copying of files.
.bazelrc Outdated Show resolved Hide resolved
go/BUILD.bazel Outdated Show resolved Hide resolved
go/BUILD.bazel Show resolved Hide resolved
go/extractor/BUILD.bazel Show resolved Hide resolved
srcs = [":tokenizer-jar"],
prefix = "tools",
renames = {
":tokenizer-jar": "tokenizer.jar",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oo okay, in that case this needs to be documented - the way it's currently written in the BUILD.bazel file it looks like a bug, not intended behavior. It is a correct reproduction of the behavior from the Makefile though.

@criemen
Copy link
Collaborator

criemen commented May 6, 2024

I think we're close to getting this in <3

Copy link
Collaborator

@criemen criemen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Happy to merge this now.

@redsun82 redsun82 merged commit 5c74beb into main May 6, 2024
22 checks passed
@redsun82 redsun82 deleted the redsun82/go branch May 6, 2024 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants