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

build: Add support for Windows #168

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 7 additions & 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-22.04', 'macos-12', 'windows-2022']
config: ['dev', 'release']
exclude:
- platform: 'macos-12'
Expand Down Expand Up @@ -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'
Expand Down
14 changes: 13 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
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.
13 changes: 13 additions & 0 deletions fetch_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
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
6 changes: 5 additions & 1 deletion setup_llvm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down