From b04854660d903ce3123e7696c527c1d5e82e7cc7 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Thu, 6 Apr 2023 12:43:31 +0900 Subject: [PATCH] build: Add support for Windows --- .github/workflows/release.yml | 2 +- docs/Development.md | 39 ++++++++++++++++++++++++++++ indexer/os/BUILD | 14 +++++----- indexer/os/Windows.cc | 49 +++++++++++++++++++++++++++++++++++ setup_llvm.bzl | 3 ++- 5 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 indexer/os/Windows.cc diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c5bdf58b..d09f5e4d 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-20.04', 'macos-12', 'windows-2022'] config: ['dev', 'release'] runs-on: ${{ matrix.platform }} env: 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/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 36be9b3a..b012ab4b 100644 --- a/setup_llvm.bzl +++ b/setup_llvm.bzl @@ -6,9 +6,10 @@ def setup_llvm_toolchain(name): "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"]