Bug 171618

Summary: [Win][Meta] Build WebKit using Clang
Product: WebKit Reporter: Don Olmstead <don.olmstead>
Component: Tools / TestsAssignee: Fujii Hironori <Hironori.Fujii>
Status: NEW ---    
Severity: Normal CC: Basuke.Suzuki, Hironori.Fujii, lforschler
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 204831, 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    
Bug Blocks:    
Attachments:
Description Flags
WIP patch
none
WIP patch
none
WIP patch
none
WIP Patch not to define WTF_COMPILER_MSVC
none
WIP Patch to define WTF_COMPILER_MSVC none

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