Skip to content

Commit aa9e2f0

Browse files
build: Add support for Windows
1 parent 972cfb4 commit aa9e2f0

File tree

5 files changed

+98
-9
lines changed

5 files changed

+98
-9
lines changed

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
matrix:
2222
# NOTE: GitHub-hosted runners for macOS are x86_64 only
2323
# https://github.com/github/roadmap/issues/528
24-
platform: ['ubuntu-22.04', 'macos-12'] # , 'windows-2022']
24+
platform: ['ubuntu-22.04', 'macos-12', 'windows-2022']
2525
config: ['dev', 'release']
2626
exclude:
2727
- platform: 'macos-12'

docs/Development.md

+39
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- [Debugging preprocessor issues](#debugging-preprocessor-issues)
1616
- [Implementation notes](#implementation-notes)
1717
- [Notes on Clang internals](#notes-on-clang-internals)
18+
- [Notes on Windows](#notes-on-windows)
1819

1920
## Install dependencies
2021

@@ -217,3 +218,41 @@ cost of assertions in Clang itself vs in our code.
217218

218219
See [docs/SourceLocation.md](/docs/SourceLocation.md) for information
219220
about how source locations are handled in Clang.
221+
222+
## Notes on Windows
223+
224+
We have limited familiarity with Windows overall,
225+
so this section includes detailed steps to (try to)
226+
build the code on Windows.
227+
228+
1. Spin up a Windows Server 2022 machine on GCP.
229+
This generally takes a bit more time than Linux machines.
230+
2. Install [Microsoft Remote Desktop](https://apps.apple.com/us/app/microsoft-remote-desktop/id1295203466)
231+
through the App Store.
232+
3. Run the GCP command: (via RDP dropdown > View gcloud command to reset password)
233+
```bash
234+
gcloud compute reset-windows-password --zone "<your zone>" --project <your project>" "<instane name>"
235+
```
236+
This will print a password.
237+
4. In the GCP UI, download the RDP file for remote login.
238+
5. Open the RDP file using Microsoft Remote Desktop.
239+
6. Enter the password from step 3.
240+
7. Start Powershell.exe as Admin and [install Chocolatey](https://docs.chocolatey.org/en-us/choco/setup#install-with-powershell.exe)
241+
8. Install [Git for Windows](https://github.com/git-for-windows/git/releases/).
242+
9. Run Git Bash as Admin and install Python and Bazelisk:
243+
```
244+
choco install -yv bazelisk python3
245+
```
246+
After this, you may need to restart Git Bash for Python to be found.
247+
If after restarting, check if `python3 --version` and `python --version` work.
248+
If `python3 --version` doesn't work, then copy over the binary
249+
```bash
250+
cp "$(which python)" "$(dirname "$(which python)")/python3"
251+
```
252+
10. Before invoking Bazel, make sure to run:
253+
```bash
254+
export MSYS2_ARG_CONV_EXCL="*"
255+
```
256+
for correctly handling `//` in Bazel targets.
257+
258+
After this, you should be able to run the build as usual.

indexer/os/BUILD

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# NOTE(ref: based-on-sorbet): Based on Sorbet's common/os package.
22
cc_library(
33
name = "os",
4-
srcs = [
5-
"Os.h",
6-
"Os.cc",
7-
] + select({
8-
"@platforms//os:linux": ["Linux.cc"],
9-
"@platforms//os:macos": ["macOS.cc"],
10-
}),
4+
srcs = glob(
5+
[
6+
"*.cc",
7+
"*.h",
8+
],
9+
allow_empty = False,
10+
),
1111
hdrs = [
1212
"Os.h",
1313
],

indexer/os/Windows.cc

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifdef _WIN32
2+
3+
#include <string>
4+
5+
#include <libloaderapi.h>
6+
#include <processthreadsapi.h>
7+
#include <windef.h>
8+
#include <windows.h>
9+
10+
#include "indexer/os/Os.h"
11+
12+
namespace scip_clang {
13+
14+
std::string exec(std::string cmd) {
15+
// FIXME(def: windows-support) Implement this if needed for addr2line
16+
return "";
17+
}
18+
19+
std::string addr2line(std::string_view programName, void const *const *addr,
20+
int count) {
21+
// FIXME(def: windows-support)
22+
return "";
23+
}
24+
25+
std::string getProgramName() {
26+
char buf[MAX_PATH];
27+
GetModuleFileNameA(nullptr, buf, MAX_PATH);
28+
return buf;
29+
}
30+
31+
bool setCurrentThreadName(std::string_view name) {
32+
std::wstring wstr = std::wstring(name.begin(), name.end());
33+
SetThreadDescription(GetCurrentThread(), wstr.c_str());
34+
return true;
35+
}
36+
37+
bool amIBeingDebugged() {
38+
// FIXME(def: windows-support)
39+
return false;
40+
}
41+
42+
bool stopInDebugger() {
43+
// FIXME(def: windows-support)
44+
return false;
45+
}
46+
47+
} // namespace scip_clang
48+
49+
#endif

setup_llvm.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ def setup_llvm_toolchain(name):
1111
"linux-x86_64": {"version": "15.0.6", "triple": "x86_64-linux-gnu-ubuntu-18.04", "sha256": "38bc7f5563642e73e69ac5626724e206d6d539fbef653541b34cae0ba9c3f036"},
1212
"darwin-arm64": {"version": "15.0.6", "triple": "arm64-apple-darwin21.0", "sha256": "32bc7b8eee3d98f72dd4e5651e6da990274ee2d28c5c19a7d8237eb817ce8d91"},
1313
"darwin-x86_64": {"version": "15.0.7", "triple": "x86_64-apple-darwin21.0", "sha256": "d16b6d536364c5bec6583d12dd7e6cf841b9f508c4430d9ee886726bd9983f1c"},
14-
"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"},
14+
"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"},
1515
}
1616
llvm_versions, sha256, strip_prefix, urls = {}, {}, {}, {}
17+
strip_prefix["windows"] = "LLVM-15.0.6-win64"
1718
for (k, v) in mapping.items():
1819
llvm_versions[k] = v["version"]
1920
sha256[k] = v["sha256"]

0 commit comments

Comments
 (0)