Bug 171618 - [Win][Meta] Build WebKit using Clang
Summary: [Win][Meta] Build WebKit using Clang
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Fujii Hironori
URL:
Keywords: InRadar
Depends on: 170833 171751 171752 171864 173889 189398 189399 189402 189538 189539 189542 189575 189612 189693 189730 189732 189733 190514 190744 191146 191959 191960 192581 192583 192584 192617 192618 192688 192693 192695 192924 193029 193035 204831 234696 255449 259090 259096 259097 259098 259119 260376 261297 262154 262506
Blocks:
  Show dependency treegraph
 
Reported: 2017-05-03 14:14 PDT by Don Olmstead
Modified: 2023-10-03 19:00 PDT (History)
5 users (show)

See Also:


Attachments
WIP patch (12.83 KB, patch)
2018-09-06 00:42 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
WIP patch (14.29 KB, patch)
2018-09-06 02:40 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
WIP patch (5.84 KB, patch)
2018-09-12 22:13 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
WIP Patch not to define WTF_COMPILER_MSVC (8.87 KB, patch)
2018-09-17 23:41 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
WIP Patch to define WTF_COMPILER_MSVC (2.81 KB, patch)
2018-09-17 23:42 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
"-T ClangCL" patch (541 bytes, patch)
2023-09-26 00:30 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Don Olmstead 2017-05-03 14:14:28 PDT
Tracking bug for supporting Clang builds on Windows.
Comment 1 Fujii Hironori 2018-09-06 00:42:15 PDT
Created attachment 349006 [details]
WIP patch

> perl Tools\Scripts\build-webkit --release --wincairo --ninja --cmakeargs="-DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_C_FLAGS=-m64 -DCMAKE_CXX_FLAGS=-m64"
Comment 2 Fujii Hironori 2018-09-06 02:40:12 PDT
Created attachment 349010 [details]
WIP patch
Comment 3 Fujii Hironori 2018-09-06 23:26:37 PDT
I uploaded build logs showing all compilation errors.
https://gist.github.com/fujii/ea5a60634e44f9c2a84cf3d3de95e2ad
I'm using LLVM-8.0.0-r339319-win64.exe.
Comment 4 Fujii Hironori 2018-09-07 00:48:11 PDT
  LLVM Project Blog: Clang is now used to build Chrome for Windows
  http://blog.llvm.org/2018/03/clang-is-now-used-to-build-chrome-for.html

I believe this is the right direction WinCairo port should follow.
Comment 5 Fujii Hironori 2018-09-12 22:13:47 PDT
Created attachment 349627 [details]
WIP patch

Compiler macro definitions should be rethought.

Current definitions:

WTF_COMPILER_GCC_OR_CLANG 0
WTF_COMPILER_CLANG 1
WTF_COMPILER_MSVC 1

* It is weird WTF_COMPILER_GCC_OR_CLANG is off even though WTF_COMPILER_CLANG is on.
* Should WTF_COMPILER_MSVC be on?
Comment 6 Fujii Hironori 2018-09-13 21:20:09 PDT
Here are the built-in macro definitions of Clang for Windows:

_MSC_VER: 1914
__GNUC__ is not defined
__clang__: 1

clang version 8.0.0 (trunk)
Target: x86_64-pc-windows-msvc

check program: https://gist.github.com/fujii/4547bda099b3568f46ee164674b1f60d
Comment 7 Fujii Hironori 2018-09-17 20:08:29 PDT
Using clang-cl to ship Windows builds - Google Group
https://groups.google.com/forum/m/#!topic/mozilla.dev.platform/wwO48xXFx0A

1443590 - Use clang-cl for Windows builds we ship to users
https://bugzilla.mozilla.org/show_bug.cgi?id=1443590

glandium.org » Blog Archive » Firefox is now built with clang LTO on all* platforms
https://glandium.org/blog/?p=3888
Comment 8 Fujii Hironori 2018-09-17 23:41:40 PDT
Created attachment 350006 [details]
WIP Patch not to define WTF_COMPILER_MSVC

WTF_COMPILER_GCC_OR_CLANG 1
WTF_COMPILER_CLANG 1
WTF_COMPILER_MSVC 0
Comment 9 Fujii Hironori 2018-09-17 23:42:43 PDT
Created attachment 350007 [details]
WIP Patch to define WTF_COMPILER_MSVC

WTF_COMPILER_GCC_OR_CLANG 0
WTF_COMPILER_CLANG 1
WTF_COMPILER_MSVC 1
Comment 10 Fujii Hironori 2018-09-18 20:16:03 PDT
Comment on attachment 350006 [details]
WIP Patch not to define WTF_COMPILER_MSVC

It seems safer that Clang for Windows builds the same code path with MSVC in the transition phase.
Comment 11 Fujii Hironori 2018-09-25 03:02:06 PDT
WinCairo port can be built by Clang for Windows (with zillions of compilation warnings).
https://trac.webkit.org/r236450

I took benchmarks:

ARES-6:

MSVC: 37.24ms
Clang: 35.85ms (faster)

Speedometer:

MSVC: 59.38 (faster)
Clang: 56.9

(I needed some trial for Clang because Clang built executable is unstable and did finish the benchmark.)

Build Time:

Ninja+MSVC: 30min (much faster)
Ninja+Clang+link.exe: 50min
Comment 12 Fujii Hironori 2018-09-25 03:03:17 PDT
(In reply to Fujii Hironori from comment #11)
> (I needed some trial for Clang because Clang built executable is unstable
> and did finish the benchmark.)

did not finish
Comment 13 Fujii Hironori 2018-09-25 18:52:47 PDT
(In reply to Fujii Hironori from comment #12)
> (In reply to Fujii Hironori from comment #11)
> > (I needed some trial for Clang because Clang built executable is unstable
> > and did finish the benchmark.)
> 
> did not finish

I was wrong. MSVC builds are also unstable for the benchmark. This is not Clang builds issue.
Comment 14 Fujii Hironori 2018-09-25 20:28:00 PDT
(In reply to Fujii Hironori from comment #11)
> Build Time:
> 
> Ninja+MSVC: 30min (much faster)
> Ninja+Clang+link.exe: 50min

This slowness is caused by the zillions of compilation warnings.
If I apply the part of Comment 8 patch to suppress the warning,
the build time becomes comparable.

> ====================================================================
>  WebKit is now built (32m:13s).
> ====================================================================
Comment 15 Fujii Hironori 2018-09-25 20:34:13 PDT
How to: Debug an Executable Not Part of a Visual Studio Solution | Microsoft Docs
https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-3.0/0bxe8ytt(v=vs.85)
Comment 16 Fujii Hironori 2018-10-23 02:44:48 PDT
* Set up

http://releases.llvm.org/download.html#7.0.0
LLVM-7.0.0-win64.exe

Add path to clang-cl and ninja

* Build

set CC=clang-cl
set CXX=clang-cl
perl Tools\Scripts\build-webkit --release --wincairo --ninja

* Remaining Tasks

- Create a Docker image with clang-cl
- Fix more compilation warnings
Comment 17 Fujii Hironori 2019-11-24 18:00:20 PST
This is a blocker for Clang 9.
  Bug 201759 – [Win][Clang 9][MiniBrowser] comip.h(174,16): error: conflicting types for '_com_ptr_t'

Keep you clang-cl 8.0.1 at the moment.
Comment 18 Fujii Hironori 2020-02-04 00:22:44 PST
New blocker: Bug 204831 – [Win] lld-link: error: /manifestdependency: is not allowed in .drectve
Comment 19 Don Olmstead 2021-02-05 08:50:33 PST
Can we close this now?
Comment 20 Fujii Hironori 2021-02-05 13:18:46 PST
There are still remaining compilation warnings.
And, I'm maintaining internal WinCairo clang-cl Jenkins jobs, but there is no public bots using clang-cl. So, I'm using this ticket to let anyone know the current status. https://trac.webkit.org/wiki/BuildingCairoOnWindows#CompileWinCairowithClang

When will WinCairo bots switch to Clang? The MSVC lambda bug is annoying. (Bug 209358)
Comment 21 Fujii Hironori 2021-04-19 13:48:53 PDT
LLVM 12.0.0 was released. I upgraded it for all internal Jenkins workers.
Comment 22 Fujii Hironori 2021-11-03 13:55:09 PDT
I upgraded the internal Jenkins workers to Clang 13.0.0.
Comment 23 Fujii Hironori 2021-12-26 18:26:33 PST
The latest WinCairo can't compile with Clang.
Bug 234696 – [Clang][Win] NotificationData.h(47,5): error: reference to 'UUID' is ambiguous
Comment 24 Fujii Hironori 2023-04-17 18:19:48 PDT
Build time:
> perl .\Tools\Scripts\build-webkit --debug --skip-library-update --no-fatal-warnings
263045@main

MSVC:  22m:13s
Clang: 25m:16s

Size of WebKitBuild directory:
$ du -hs WebKitBuild/Debug

MSVC:  14G
Clang: 7.5G
Comment 25 Ian Grunert 2023-07-22 19:20:14 PDT
This blocks FTL on windows (bug 145366) - the generated AirOpcodeGenerated.h contains code that builds on clang but warns on MSVC.

Could fix the generator to stop spitting out switch statements with a default case and no case labels, but it might be easier to wait till the switch to clang happens?
Comment 26 Ian Grunert 2023-07-23 13:54:51 PDT
Went ahead and fixed those switch statements in bug 259429
Comment 27 Fujii Hironori 2023-09-26 00:30:57 PDT
Created attachment 467870 [details]
"-T ClangCL" patch

It's possible to use CMake Visual Studio generator and clang-cl extension.
However, there are two problems at the moment.
1. You have to apply a patch to set "-T ClangCL" CMake switch.
2. CMake Visual Studio generator ignores some compiler warning disabling switches like /wd4100.
   It reports compiler warnings. You have to give --no-fatal-warnings switches.

How to build WebKit Windows port with Visual Studio and clang-cl

1. Install LLVM extension.
  https://learn.microsoft.com/en-us/cpp/build/clang-support-msbuild
2. Apply the "-T ClangCL" patch
3. Invoke "perl .\Tools\Scripts\build-webkit --no-ninja --no-fatal-warnings" in WebKit command prompt.

Or, you can open the solution file:

3. Invoke "perl .\Tools\Scripts\build-webkit --no-ninja --no-fatal-warnings --generate-project-only" in WebKit command prompt.
4. Invoke "devenv WebKitBuild\Release\WebKit.sln" in WebKit command prompt.
Comment 28 Fujii Hironori 2023-09-26 13:15:07 PDT
We don't need the patch. 

> perl .\Tools\Scripts\build-webkit --debug --no-fatal-warnings --no-ninja --cmakeargs="-T ClangCL"
Comment 29 Fujii Hironori 2023-10-03 18:59:56 PDT
The build instruction has been updated.
https://github.com/WebKit/Documentation/commit/739ce4449adb3de8e272a4221b67468b404644e2
No remaining tasks. Closed.
Comment 30 Radar WebKit Bug Importer 2023-10-03 19:00:29 PDT
<rdar://problem/116439320>