Skip to content

Commit

Permalink
build: Add support for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src committed Apr 10, 2023
1 parent 833bd67 commit b048546
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
39 changes: 39 additions & 0 deletions docs/Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 "<your zone>" --project <your project>" "<instane name>"
```
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.
14 changes: 7 additions & 7 deletions indexer/os/BUILD
Original file line number Diff line number Diff line change
@@ -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",
],
Expand Down
49 changes: 49 additions & 0 deletions indexer/os/Windows.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifdef _WIN32

#include <string>

#include <libloaderapi.h>
#include <processthreadsapi.h>
#include <windef.h>
#include <windows.h>

#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
3 changes: 2 additions & 1 deletion setup_llvm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit b048546

Please sign in to comment.