diff --git a/.bazelrc b/.bazelrc index 1900d62c..ad21095c 100644 --- a/.bazelrc +++ b/.bazelrc @@ -59,3 +59,5 @@ build:dev --copt="-Og" # For testing against large projects locally build:release --copt="-O2" build:release --config=stacktraces +# Zig uses UBSan by default +build:release --copt="-fno-sanitize=undefined" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0c82a1ae..badce09e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,7 @@ jobs: matrix: # NOTE: GitHub-hosted runners for macOS are x86_64 only # https://github.com/github/roadmap/issues/528 - platform: ['ubuntu-20.04', 'macos-12'] # , 'windows-2022'] + platform: ['ubuntu-22.04', 'macos-12', 'windows-2022'] config: ['dev', 'release'] exclude: - platform: 'macos-12' @@ -70,11 +70,17 @@ jobs: { echo "startup --host_jvm_args=-Xmx$BAZEL_MEM" echo "build --remote_cache=$CI_BAZEL_REMOTE_CACHE --google_default_credentials" + echo "build --toolchain_resolution_debug '.*'" } > ci.bazelrc bazel build //indexer:scip-clang --config="$CONFIG" --execution_log_binary_file=log env: CONFIG: ${{ matrix.config }} CI_BAZEL_REMOTE_CACHE: 'https://storage.googleapis.com/sourcegraph_bazel_cache' + - name: '๐Ÿงช Test scip-clang' + run: + bazel test //test --config="$CONFIG" + env: + CONFIG: ${{ matrix.config }} - name: '๐Ÿ”Ž Identify OS' run: echo "OS=$(uname -s | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV" - name: '๐Ÿชต Upload log' diff --git a/WORKSPACE b/WORKSPACE index b9b1a4ad..bca3c071 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -4,6 +4,17 @@ load("//:fetch_deps.bzl", "fetch_direct_dependencies") fetch_direct_dependencies() +load("@bazel-zig-cc//toolchain:defs.bzl", zig_toolchains = "toolchains") + +zig_toolchains() + +# Register the Zig toolchain before the grailbio one +# so that the Zig one is preferred on Linux. +register_toolchains( + "@zig_sdk//toolchain:linux_amd64_gnu.2.19", + "@zig_sdk//toolchain:linux_arm64_gnu.2.28", +) + # Setup the toolchain before setting up other dependencies load("@com_grail_bazel_toolchain//toolchain:deps.bzl", "bazel_toolchain_dependencies") @@ -14,10 +25,11 @@ load("//:setup_llvm.bzl", "setup_llvm_toolchain") setup_llvm_toolchain(name = "llvm_toolchain") load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains") -load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") llvm_register_toolchains() +load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") + python_register_toolchains( name = "python_3_10", # Remove this once agents stop running tests as root diff --git a/docs/Development.md b/docs/Development.md index 81574d67..f83d08ab 100644 --- a/docs/Development.md +++ b/docs/Development.md @@ -15,6 +15,7 @@ - [Debugging preprocessor issues](#debugging-preprocessor-issues) - [Implementation notes](#implementation-notes) - [Notes on Clang internals](#notes-on-clang-internals) +- [Notes on Windows](#notes-on-windows) ## Install dependencies @@ -217,3 +218,41 @@ cost of assertions in Clang itself vs in our code. See [docs/SourceLocation.md](/docs/SourceLocation.md) for information about how source locations are handled in Clang. + +## Notes on Windows + +We have limited familiarity with Windows overall, +so this section includes detailed steps to (try to) +build the code on Windows. + +1. Spin up a Windows Server 2022 machine on GCP. + This generally takes a bit more time than Linux machines. +2. Install [Microsoft Remote Desktop](https://apps.apple.com/us/app/microsoft-remote-desktop/id1295203466) + through the App Store. +3. Run the GCP command: (via RDP dropdown > View gcloud command to reset password) + ```bash + gcloud compute reset-windows-password --zone "" --project " "" + ``` + This will print a password. +4. In the GCP UI, download the RDP file for remote login. +5. Open the RDP file using Microsoft Remote Desktop. +6. Enter the password from step 3. +7. Start Powershell.exe as Admin and [install Chocolatey](https://docs.chocolatey.org/en-us/choco/setup#install-with-powershell.exe) +8. Install [Git for Windows](https://github.com/git-for-windows/git/releases/). +9. Run Git Bash as Admin and install Python and Bazelisk: + ``` + choco install -yv bazelisk python3 + ``` + After this, you may need to restart Git Bash for Python to be found. + If after restarting, check if `python3 --version` and `python --version` work. + If `python3 --version` doesn't work, then copy over the binary + ```bash + cp "$(which python)" "$(dirname "$(which python)")/python3" + ``` +10. Before invoking Bazel, make sure to run: + ```bash + export MSYS2_ARG_CONV_EXCL="*" + ``` + for correctly handling `//` in Bazel targets. + +After this, you should be able to run the build as usual. diff --git a/fetch_deps.bzl b/fetch_deps.bzl index 1a705ceb..ed08d5b7 100644 --- a/fetch_deps.bzl +++ b/fetch_deps.bzl @@ -16,6 +16,7 @@ _SCIP_COMMIT = "aa0e511dcfefbacc3b96dcc2fe2abd9894416b1e" # in the types for which we implement hashing and comparison in # indexer/ScipExtras.{h,cc} +_BAZEL_ZIG_CC_VERSION = "v1.0.1" _DOCTEST_VERSION = "2.4.9" _DTL_VERSION = "1.20" _RULES_PYTHON_VERSION = "0.18.1" @@ -46,6 +47,18 @@ def fetch_direct_dependencies(): ], ) + http_archive( + # The repo hard-codes this name in internal functions, + # so use kebab-case instead of camel case. + name = "bazel-zig-cc", + sha256 = "e9f82bfb74b3df5ca0e67f4d4989e7f1f7ce3386c295fd7fda881ab91f83e509", + strip_prefix = "bazel-zig-cc-{}".format(_BAZEL_ZIG_CC_VERSION), + urls = [ + "https://mirror.bazel.build/github.com/uber/bazel-zig-cc/releases/download/{0}/{0}.tar.gz".format(_BAZEL_ZIG_CC_VERSION), + "https://github.com/uber/bazel-zig-cc/releases/download/{0}/{0}.tar.gz".format(_BAZEL_ZIG_CC_VERSION), + ], + ) + http_archive( name = "com_github_nelhage_rules_boost", sha256 = "dc9140b868de82ae46dd44da73a7d9749b680b1e7d63b0912288c2de2cabcb1d", diff --git a/indexer/os/BUILD b/indexer/os/BUILD index a475a59e..e21239df 100644 --- a/indexer/os/BUILD +++ b/indexer/os/BUILD @@ -1,13 +1,13 @@ # NOTE(ref: based-on-sorbet): Based on Sorbet's common/os package. cc_library( name = "os", - srcs = [ - "Os.h", - "Os.cc", - ] + select({ - "@platforms//os:linux": ["Linux.cc"], - "@platforms//os:macos": ["macOS.cc"], - }), + srcs = glob( + [ + "*.cc", + "*.h", + ], + allow_empty = False, + ), hdrs = [ "Os.h", ], diff --git a/indexer/os/Windows.cc b/indexer/os/Windows.cc new file mode 100644 index 00000000..6f29ded3 --- /dev/null +++ b/indexer/os/Windows.cc @@ -0,0 +1,49 @@ +#ifdef _WIN32 + +#include + +#include +#include +#include +#include + +#include "indexer/os/Os.h" + +namespace scip_clang { + +std::string exec(std::string cmd) { + // FIXME(def: windows-support) Implement this if needed for addr2line + return ""; +} + +std::string addr2line(std::string_view programName, void const *const *addr, + int count) { + // FIXME(def: windows-support) + return ""; +} + +std::string getProgramName() { + char buf[MAX_PATH]; + GetModuleFileNameA(nullptr, buf, MAX_PATH); + return buf; +} + +bool setCurrentThreadName(std::string_view name) { + std::wstring wstr = std::wstring(name.begin(), name.end()); + SetThreadDescription(GetCurrentThread(), wstr.c_str()); + return true; +} + +bool amIBeingDebugged() { + // FIXME(def: windows-support) + return false; +} + +bool stopInDebugger() { + // FIXME(def: windows-support) + return false; +} + +} // namespace scip_clang + +#endif \ No newline at end of file diff --git a/setup_llvm.bzl b/setup_llvm.bzl index 2289a119..73c30a86 100644 --- a/setup_llvm.bzl +++ b/setup_llvm.bzl @@ -4,13 +4,17 @@ def setup_llvm_toolchain(name): # NOTE: The ASan build uses paths which involve the version. # Keep the version list in sync with settings.bzl mapping = { + # Even though we're using zig cc on Linux, keep these + # in to keep clang-format working in CI until we figure + # out a more lightweight solution. "linux-aarch64": {"version": "15.0.6", "triple": "aarch64-linux-gnu", "sha256": "8ca4d68cf103da8331ca3f35fe23d940c1b78fb7f0d4763c1c059e352f5d1bec"}, "linux-x86_64": {"version": "15.0.6", "triple": "x86_64-linux-gnu-ubuntu-18.04", "sha256": "38bc7f5563642e73e69ac5626724e206d6d539fbef653541b34cae0ba9c3f036"}, "darwin-arm64": {"version": "15.0.6", "triple": "arm64-apple-darwin21.0", "sha256": "32bc7b8eee3d98f72dd4e5651e6da990274ee2d28c5c19a7d8237eb817ce8d91"}, "darwin-x86_64": {"version": "15.0.7", "triple": "x86_64-apple-darwin21.0", "sha256": "d16b6d536364c5bec6583d12dd7e6cf841b9f508c4430d9ee886726bd9983f1c"}, - "windows": {"version": "15.0.6", "sha256": "22e2f2c38be4c44db7a1e9da5e67de2a453c5b4be9cf91e139592a63877ac0a2", "url": "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.6/LLVM-15.0.6-win64.exe"}, + "windows": {"version": "15.0.6", "sha256": "8c0305c569391fb842c3a1edb07e63a2c0145a2a601d5a87992ae402b437c48f", "url": "https://github.com/sourcegraph/llvm-toolchain-archives/releases/download/v0-20223-04-10/LLVM-15.0.6-win64.tar.xz"}, } llvm_versions, sha256, strip_prefix, urls = {}, {}, {}, {} + strip_prefix["windows"] = "LLVM-15.0.6-win64" for (k, v) in mapping.items(): llvm_versions[k] = v["version"] sha256[k] = v["sha256"]