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

Add Swift extractor to Code Scanning #16035

Closed
wants to merge 12 commits into from

Conversation

calumgrant
Copy link
Contributor

@calumgrant calumgrant commented Mar 25, 2024

No description provided.

@calumgrant calumgrant requested a review from redsun82 March 26, 2024 11:10
@calumgrant calumgrant marked this pull request as ready for review March 26, 2024 11:11
@calumgrant calumgrant requested a review from a team as a code owner March 26, 2024 11:11
@criemen
Copy link
Collaborator

criemen commented Mar 26, 2024

Search for bazel in https://docs.github.com/en/enterprise-cloud@latest/code-security/codeql-cli/getting-started-with-the-codeql-cli/preparing-your-code-for-codeql-analysis for the options you'll want to use

@redsun82
Copy link
Contributor

hmm the error is weird (and as you can see it's not really related to the options you removed). Might be a bug with abseil's own bazel configuration. Let me look.

@redsun82
Copy link
Contributor

maybe try to update abseil to the latest version with

bazel_dep(name = "abseil-cpp", version = "20240116.1")

in MODULE.bazel. You can probably revert the last commit.

@calumgrant
Copy link
Contributor Author

The build command worked once so I presumed that whatever I changed was related to those changes!

@redsun82
Copy link
Contributor

The build command worked once so I presumed that whatever I changed was related to those changes!

Yeah, it probably does (although it shouldn't), I was just saying it's probably not related to those specific options but to the other ones (and a misbehaviour by abseil...). Honestly, I'd probably leave the flags aside if this proves to be too problematic. I think they are overkill, and probably very relevant for local database extraction (where you might have an already running untraced bazel server and a warm cache), but not very much so in a clean runner environment. What do you think @criemen?

@redsun82
Copy link
Contributor

I could reproduce this locally with --spawn_strategy=local. It's pretty weird that a more lax sandboxing leads to that error, but it's probably a bug with abseil. I'll report it. In the meantime I'd suggest we go without the suggested flags.

@criemen
Copy link
Collaborator

criemen commented Mar 26, 2024

Yeah, if this causes problems, you can drop everything besides --spawn_strategy=local, as long as we execute this on the standard ephemeral action runners.

@calumgrant
Copy link
Contributor Author

I get the same problems with --spawn_strategy=local on a Linux machine. But we DO need this as we only seeing 16 compilation units in telemetry, which isn't right.

@redsun82
Copy link
Contributor

hm, ok. I couldn't reproduce on a standalone abseil checkout, so something's off with the module import, I have an idea for a workaround, let me check

@criemen
Copy link
Collaborator

criemen commented Mar 26, 2024

There's a bazel bug/design shortcoming where one header shadows another when the sandbox is disabled, thus leading to compile errors (this requires two headers of the same name). We ran into this at a customers, too. Not sure if this is what's happening with abseil, though.

@redsun82
Copy link
Contributor

as a workaround, you can build @absl//absl/strings with the normal strategy, and then the extractor with the local one. Analysis will miss the absl strings library, but that could be good enough?

bazel build @absl//absl/strings
bazel run //swift:create-extractor-pack --spawn_strategy=local

@redsun82
Copy link
Contributor

redsun82 commented Mar 26, 2024

@calumgrant @criemen found a cleaner workaround, the issue is some weird interaction between a new feature of clang and bazel and local strategy.

https://maskray.me/blog/2022-09-25-layering-check-with-clang

adding --features=-layering_check should solve the issue 👍

@criemen
Copy link
Collaborator

criemen commented Mar 26, 2024

Great find! In that case, I'd like to bring back all the options, and document why we disable the layering check here.

Edit: I'll be on PTO, please proceed without my input on this task.

@redsun82
Copy link
Contributor

aaand there's a bug already open: bazelbuild/bazel#21592

@@ -40,7 +40,7 @@ jobs:
uses: github/codeql-action/init@main
# Override language selection by uncommenting this and choosing your languages
with:
languages: csharp
languages: csharp, cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't comment on the Bazel changes, but consider matrixing the analysis over languages (e.g. see the template here https://github.com/actions/starter-workflows/blob/main/code-scanning/codeql.yml). This is what we recommend to customers as it means the analyses can run in parallel, and if one fails it doesn't disrupt the other.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding both languages un-matrixed will also break our existing analysis categories and alert matching: since currently no category is specified it will fall back to the language.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think when no category is specified we fall back to the workflow name, job name, and matrix parameters e.g. here .github/workflows/codeql-analysis.yml:CodeQL-Build. So actually matrixing the build would create new histories when it comes to alert matching. I think that's probably a price we're willing to pay, but it's less of a clear cut win.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah my mistake, wrong way round. Specifying the category when we do that is probably worthwhile then.

Copy link
Contributor Author

@calumgrant calumgrant Mar 27, 2024

Choose a reason for hiding this comment

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

How do you feel about creating a second workflow file for C++ analysis of the Swift extractor? The build commands are completely different and independent.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, seems like a good idea to me! Then it shouldn't disrupt the current analysis state in any way

@calumgrant
Copy link
Contributor Author

I created a second PR #16071 where the C++ analysis is performed in a separate workflow file. If this approach is better, we can close this one.

@calumgrant
Copy link
Contributor Author

Closed in favour of #16071

@calumgrant calumgrant closed this Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants