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

Add native support for Windows #452

Merged
merged 1 commit into from
Apr 3, 2023
Merged

Conversation

mrbbot
Copy link
Contributor

@mrbbot mrbbot commented Mar 16, 2023

(depends on capnproto/capnproto#1640)

Hey! 👋 This PR adds native support for Windows to workerd. The primary aim here is to get Miniflare 3 and wrangler dev --experimental-local running on Windows natively, for local development and testing. This is one of the last few things we need to do before graduating --experimental-local to --local.

This PR is not intended to allow workerd to run in production on Windows servers. With that in mind, a few features haven’t been implemented, notably configuration watching and creating single executable binaries. We may consider adding these later.

Windows setup instructions have been added to the README.

We use LLVM's MSVC-compatible compiler driver clang-cl to compile on Windows, as opposed to using MSVC directly. This enables us to use the "same" compiler frontend on Linux, macOS, and Windows, massively reducing the effort required to compile workerd on Windows. Notably, this provides proper support for #pragma once when using symlinked virtual includes, __atomic_* functions, a standards-compliant preprocessor, support for GNU statement expressions used by some KJ macros, and understands the .c++ extension by default.


TODO:

@mrbbot mrbbot force-pushed the bcoll/windows-clang branch from 34e9abf to f5ba4ff Compare March 16, 2023 17:43
WORKSPACE Outdated Show resolved Hide resolved
patches/v8/0009-Allow-Windows-builds-under-Bazel.patch Outdated Show resolved Hide resolved
Comment on lines +150 to +152
auto request = client->request(kj::HttpMethod::GET, urlStr, headers);
return context.awaitIo(js,
client->request(kj::HttpMethod::GET, urlStr, headers).response,
kj::mv(request.response),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this change, and similar changes for KV list and WebSocket fetch, we were seeing the following error:

workerd/jsg/util.c++:423: error: e = kj/_virtual_includes/kj\kj/memory.h:258: failed: expected ptr != nullptr; null Own<> dereference
stack: 7ff74084ca28 7ff74084b33a 7ff7406c84ad 7ff74156873a 7ff74156a07d 7ff741567ec2 7ff741567ddb 7ff740b06b46 7ff740b066c6 7ff740b0626a 7ff740b061e4 7ff740b061a0 7ff73ce30d82 7ff73ce2e936 7ff73ce2b727 7ff73ce2ad0b 
7ff741dffafb 7ff741d77feb 7ff741d77feb 7ff741d7675b 7ff741d7635a 7ff73d208d2b 7ff73d203ff0 7ff73d20242f 7ff73ccfba9f 7ff7409dbb80 7ff7409db9a2 7ff741492de8 7ff74148b5b6 7ff7415319c2 7ff740f9a3ce 7ff740f9a216; sentryErrorContext = jsgInternalError
workerd/io/worker.c++:1686: info: uncaught exception; source = Uncaught (in promise); exception = Error: internal error
workerd/io/io-context.c++:381: info: uncaught exception; exception = workerd/jsg/_virtual_includes/jsg\workerd/jsg/value.h:1347: failed: jsg.Error: internal error
stack: 0 7ff7408529b6 7ff74153ee1d 7ff74153ed55 7ff74153e996 7ff7408156bf 7ff74080b48f 7ff74080b39b 7ff74080b63c 7ff740f9b670 7ff7408156bf 7ff74080b48f 7ff74080b39b 7ff74080d746 7ff74080d604 7ff74080b63c 7ff740f9c370 7ff7408156bf 7ff74080b48f 7ff74080b39b 7ff74080c8be 7ff740807b1d 7ff740814c42 7ff7408091ca 7ff740808ddf 7ff73ca1b750 7ff73ca259b1 7ff73ca2561c 7ff73ca255f7 7ff73ca255cc 7ff73ca2554d 7ff73ca25513
workerd/server/server.c++:2244: error: Uncaught exception: workerd/jsg/_virtual_includes/jsg\workerd/jsg/value.h:1347: failed: remote.jsg.Error: internal error
stack: 0 7ff7408529b6 7ff74153ee1d 7ff74153ed55 7ff74153e996 7ff7408156bf 7ff74080b48f 7ff74080b39b 7ff74080b63c 7ff740f9b670 7ff7408156bf 7ff74080b48f 7ff74080b39b 7ff74080d746 7ff74080d604 7ff74080b63c 7ff740f9c370 7ff7408156bf 7ff74080b48f 7ff74080b39b 7ff74080c8be 7ff740807b1d 7ff740814c42 7ff7408091ca 7ff740808ddf 7ff73ca1b750 7ff73ca259b1 7ff73ca2561c 7ff73ca255f7 7ff73ca255cc 7ff73ca2554d 7ff73ca25513

I'm not too sure what's going on here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably because client is kj::mved as part of the same statement (see next line of code). It is unspecified in what order these happen, and compilers can differ. It seems when compiling for Windows, Clang is doing the kj::mv before it attempts to dereference client, and so by the time it dereferences, it is moved away.

I'm surprised that Clang's behavior differs between Linux and Windows, though. I would normally expect a particular compiler to be consistent across platforms. Maybe they felt they needed to match MSVC on Windows? I wonder if there's a flag we can use to control this. It's going to be pretty annoying for those of us developing on Linux to have to deal with these problems, which won't be noticed until CI time...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, looking at the flags, I can't see anything that would control this. I'm guessing it would be a /Zc: option, but there's only:

/Zc:alignedNew-         Disable C++17 aligned allocation functions
/Zc:alignedNew          Enable C++17 aligned allocation functions
/Zc:char8_t-            Disable char8_t from c++2a
/Zc:char8_t             Enable char8_t from C++2a
/Zc:dllexportInlines-   Do not dllexport/dllimport inline member functions of dllexport/import classes
/Zc:dllexportInlines    dllexport/dllimport inline member functions of dllexport/import classes (default)
/Zc:sizedDealloc-       Disable C++14 sized global deallocation functions
/Zc:sizedDealloc        Enable C++14 sized global deallocation functions
/Zc:strictStrings       Treat string literals as const
/Zc:threadSafeInit-     Disable thread-safe initialization of static variables
/Zc:threadSafeInit      Enable thread-safe initialization of static variables
/Zc:trigraphs-          Disable trigraphs (default)
/Zc:trigraphs           Enable trigraphs
/Zc:twoPhase-           Disable two-phase name lookup in templates (default)
/Zc:twoPhase            Enable two-phase name lookup in templates
/Zc:wchar_t-            Disable C++ builtin type wchar_t
/Zc:wchar_t             Enable C++ builtin type wchar_t (default)

There's also these, but they aren't enabled by default:

-fms-compatibility-version=<value>
                        Dot-separated value representing the Microsoft compiler version number to report in _MSC_VER (0 = don't define it (default))
-fms-compatibility      Enable full Microsoft Visual C++ compatibility
-fms-extensions         Accept some non-standard constructs supported by the Microsoft compiler

src/workerd/io/BUILD.bazel Outdated Show resolved Hide resolved
src/workerd/jsg/jsg.c++ Show resolved Hide resolved
src/workerd/server/server-test.c++ Show resolved Hide resolved
src/workerd/tools/BUILD.bazel Show resolved Hide resolved
src/workerd/util/sqlite.c++ Show resolved Hide resolved
@mrbbot mrbbot requested a review from mikea March 16, 2023 17:44
@mrbbot mrbbot marked this pull request as ready for review March 16, 2023 17:44
README.md Show resolved Hide resolved
src/workerd/jsg/setup.c++ Outdated Show resolved Hide resolved
.bazelrc Outdated Show resolved Hide resolved
@mrbbot
Copy link
Contributor Author

mrbbot commented Mar 17, 2023

190a151 should've fixed the flaky blob test. See the commit description for rationale.

@mrbbot mrbbot force-pushed the bcoll/windows-clang branch from 59d15b7 to 581f172 Compare March 17, 2023 22:11
.bazelversion Show resolved Hide resolved
@mrbbot mrbbot requested review from kentonv and fhanau March 18, 2023 19:33
src/workerd/api/crypto.c++ Outdated Show resolved Hide resolved
src/workerd/api/crypto.c++ Outdated Show resolved Hide resolved
exclude = [
"trace.h",
],
# `trace.h` should really be excluded here, but doing so causes the build to fail on
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird, is it because there's a relative (quoted) include that needs to be converted to an absolute (angle-bracketed) include somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I tried replacing all the relative includes in src/workerd/io with absolutes (and vice-versa), and neither seemed to help. 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks kinda similar to bazelbuild/bazel#6337, but that should've been fixed...

src/workerd/io/compatibility-date.c++ Outdated Show resolved Hide resolved
src/workerd/io/compatibility-date.c++ Show resolved Hide resolved
src/workerd/io/compatibility-date.c++ Show resolved Hide resolved
src/workerd/server/workerd.c++ Show resolved Hide resolved
src/workerd/server/workerd.c++ Outdated Show resolved Hide resolved
src/workerd/server/workerd.c++ Outdated Show resolved Hide resolved
src/workerd/util/sqlite.c++ Show resolved Hide resolved
@mrbbot mrbbot force-pushed the bcoll/windows-clang branch from b961323 to 3ec4c77 Compare March 29, 2023 11:34
@mrbbot
Copy link
Contributor Author

mrbbot commented Mar 29, 2023

Last force-push is a rebase. Should be ready for another review assuming CI passes. Will squash all these fixups before merging. 👍

@mrbbot mrbbot force-pushed the bcoll/windows-clang branch from 0fbe29c to 2f4c551 Compare March 30, 2023 10:30
@mrbbot
Copy link
Contributor Author

mrbbot commented Mar 30, 2023

Rebasing again 👍

.bazelversion Show resolved Hide resolved
@mrbbot mrbbot requested review from kentonv and Warfields March 30, 2023 20:16
Copy link
Member

@kentonv kentonv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting this to "request changes" because fixups need to be squashed, otherwise it looks good to merge.

@mrbbot mrbbot force-pushed the bcoll/windows-clang branch from 2f4c551 to 943b861 Compare March 31, 2023 21:22
@mrbbot
Copy link
Contributor Author

mrbbot commented Mar 31, 2023

Awesome, squashed 😀

@mrbbot mrbbot requested a review from kentonv March 31, 2023 21:25
@kentonv kentonv dismissed Warfields’s stale review March 31, 2023 21:56

We don't need a separate PR to update bazel.

@mrbbot mrbbot force-pushed the bcoll/windows-clang branch from 943b861 to 5e10e30 Compare April 1, 2023 14:44
@mrbbot mrbbot merged commit 17a927f into cloudflare:main Apr 3, 2023
@mrbbot
Copy link
Contributor Author

mrbbot commented Apr 3, 2023

Rebased before merging 👍

mrbbot added a commit to cloudflare/miniflare that referenced this pull request Apr 5, 2023
As of cloudflare/workerd#452, `workerd` supports Windows' natively.
This change upgrades `workerd`, then removes the WSL and Docker
runtime shells.
mrbbot added a commit to cloudflare/miniflare that referenced this pull request Apr 5, 2023
As of cloudflare/workerd#452, `workerd` supports Windows' natively.
This change upgrades `workerd`, then removes the WSL and Docker
runtime shells. It also `Cherry`picks #509, to allow Miniflare
development on Windows too.
mrbbot added a commit to cloudflare/miniflare that referenced this pull request Apr 5, 2023
As of cloudflare/workerd#452, `workerd` supports Windows' natively.
This change upgrades `workerd`, then removes the WSL and Docker
runtime shells. It also `Cherry`picks #509, to allow Miniflare
development on Windows too.
mrbbot added a commit to cloudflare/miniflare that referenced this pull request Apr 5, 2023
As of cloudflare/workerd#452, `workerd` supports Windows' natively.
This change upgrades `workerd`, then removes the WSL and Docker
runtime shells. It also `Cherry`picks #509, to allow Miniflare
development on Windows too.
mrbbot added a commit to cloudflare/miniflare that referenced this pull request Apr 5, 2023
As of cloudflare/workerd#452, `workerd` supports Windows' natively.
This change upgrades `workerd`, then removes the WSL and Docker
runtime shells. It also `Cherry`picks #509, to allow Miniflare
development on Windows too.
mrbbot added a commit to cloudflare/miniflare that referenced this pull request Apr 12, 2023
As of cloudflare/workerd#452, `workerd` supports Windows' natively.
This change upgrades `workerd`, then removes the WSL and Docker
runtime shells. It also `Cherry`picks #509, to allow Miniflare
development on Windows too.
mrbbot added a commit to cloudflare/miniflare that referenced this pull request Apr 17, 2023
As of cloudflare/workerd#452, `workerd` supports Windows' natively.
This change upgrades `workerd`, then removes the WSL and Docker
runtime shells. It also `Cherry`picks #509, to allow Miniflare
development on Windows too.
mrbbot added a commit to cloudflare/miniflare that referenced this pull request Apr 17, 2023
As of cloudflare/workerd#452, `workerd` supports Windows' natively.
This change upgrades `workerd`, then removes the WSL and Docker
runtime shells. It also `Cherry`picks #509, to allow Miniflare
development on Windows too.
@mrbbot mrbbot deleted the bcoll/windows-clang branch August 15, 2023 10:44
mrbbot added a commit to cloudflare/workers-sdk that referenced this pull request Oct 31, 2023
As of cloudflare/workerd#452, `workerd` supports Windows' natively.
This change upgrades `workerd`, then removes the WSL and Docker
runtime shells. It also `Cherry`picks #509, to allow Miniflare
development on Windows too.
mrbbot added a commit to cloudflare/workers-sdk that referenced this pull request Nov 1, 2023
As of cloudflare/workerd#452, `workerd` supports Windows' natively.
This change upgrades `workerd`, then removes the WSL and Docker
runtime shells. It also `Cherry`picks #509, to allow Miniflare
development on Windows too.
mrbbot added a commit to cloudflare/workers-sdk that referenced this pull request Nov 1, 2023
As of cloudflare/workerd#452, `workerd` supports Windows' natively.
This change upgrades `workerd`, then removes the WSL and Docker
runtime shells. It also `Cherry`picks #509, to allow Miniflare
development on Windows too.
mrbbot added a commit to cloudflare/workers-sdk that referenced this pull request Nov 1, 2023
As of cloudflare/workerd#452, `workerd` supports Windows' natively.
This change upgrades `workerd`, then removes the WSL and Docker
runtime shells. It also `Cherry`picks #509, to allow Miniflare
development on Windows too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants