Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

use clang on Windows#17407

Merged
dnfield merged 10 commits intoflutter:masterfrom
dnfield:win_clang
Apr 29, 2020
Merged

use clang on Windows#17407
dnfield merged 10 commits intoflutter:masterfrom
dnfield:win_clang

Conversation

@dnfield
Copy link
Contributor

@dnfield dnfield commented Mar 30, 2020

This uses a build of Clang 8.0.0 on Windows, fetched from Chromium.

It adds a script similar to what Chromium does for copying msdia*.dll to the right spot.

This works locally, but spouts tons of warnings from Dart, libpng, angle, etc. We could soften this for now by not making clang on by default, or just use it because it'll make CI more stable.

Copy link
Contributor

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

or just use it because it'll make CI more stable.

Let'd do this. We can suppress warning in native compiler configs in the buildroot for targets that we don't control and patch the rest.

@rmacnak-google for thoughts on wiring this up in the Dart buildroot as well.

'llvm-build', 'Release+Asserts'))


def GetDiaDll():
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this DLL for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what Chromium does upstream to build with. Without this, the build fails because it can't find expected symbols. Don't really have more details beyond that.

},

# TODO(fxb/4443): Remove this when Fuchsia can provide the Windows Clang Toolchain
'src/third_party/llvm-build/Release+Asserts': {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't this just be //build/toolchain like for all other platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now the buildroot is looking for it here. We can patch buildroot for this, but I think for now this makes it clearer we're not using Fuchsia clang. WDYT?

tools/gn Outdated
gn_args['is_debug'] = args.unoptimized
gn_args['android_full_debug'] = args.target_os == 'android' and args.unoptimized
gn_args['is_clang'] = not sys.platform.startswith(('cygwin', 'win'))
gn_args['is_clang'] = True
Copy link
Contributor

Choose a reason for hiding this comment

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

Love it.

Copy link
Contributor

Choose a reason for hiding this comment

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

We have a --clang/--no-clang argument (with clang being the default). We should honor it here, so that someone who wants to build with VS instead of clang can do so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

tools/dia_dll.py Outdated
if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))):
dia_path = os.path.join(win_sdk_dir, '..', 'DIA SDK', 'bin', 'amd64')
else:
if 'GYP_MSVS_OVERRIDE_PATH' not in os.environ:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have existing use of this environment variable? If not, we should name it something else, rather than use a legacy name based on a build system that Flutter has never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is used by depot_tools. I'd rather avoid creating a new one that might not play well with the existing buildroot/depot_tools

tools/dia_dll.py Outdated
if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))):
dia_path = os.path.join(win_sdk_dir, '..', 'DIA SDK', 'bin', 'amd64')
else:
if 'GYP_MSVS_OVERRIDE_PATH' not in os.environ:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: prefer "if (foo) ... else ..." to "if (!foo) ... else ..." constructions in general, as they read more naturally (due to the lack of double-negative).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

# Bump after VC updates.
DIA_DLL = {
'2013': 'msdia120.dll',
'2015': 'msdia140.dll',
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we support 2013 or 2015?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, but the upstream script had it and I figured it may be helpful when trying to figure out how to add new ones.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, the upstream script has it because they have supported these versions in the past. I was thinking leave the map construction here even though it's not currently needed, to make it easy to change in the future, but remove the old entries that we will never use.

tools/gn Outdated
gn_args['is_debug'] = args.unoptimized
gn_args['android_full_debug'] = args.target_os == 'android' and args.unoptimized
gn_args['is_clang'] = not sys.platform.startswith(('cygwin', 'win'))
gn_args['is_clang'] = True
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a --clang/--no-clang argument (with clang being the default). We should honor it here, so that someone who wants to build with VS instead of clang can do so.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM

# Bump after VC updates.
DIA_DLL = {
'2013': 'msdia120.dll',
'2015': 'msdia140.dll',
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, the upstream script has it because they have supported these versions in the past. I was thinking leave the map construction here even though it's not currently needed, to make it easy to change in the future, but remove the old entries that we will never use.

@rmacnak-google
Copy link
Contributor

Why? Building everything with Clang is an anti-goal. Toolchain diversity should be maintained.

@dnfield
Copy link
Contributor Author

dnfield commented Apr 1, 2020

@rmacnak-google - this patch will still use MSVC for linking.

GOMA is dropping support for MSVC. Building without GOMA is very slow. We also run into lots of little idiosyncrosies between MSVC and Clang. And anecdotally, Chrome has been happier with building on Clang vs MSVC .. or so I've heard third hand.

@stuartmorgan-g
Copy link
Contributor

@rmacnak-google See flutter/flutter#16256 and flutter/flutter#48831

Building everything with Clang is an anti-goal.

Based on which Flutter principle?

Toolchain diversity should be maintained.

Not at the expense of actually being able to build the product we want to build.

@chinmaygarde
Copy link
Contributor

Based on which Flutter principle?

That just seems like sound engineering principle to me. And in this case, it has helped us as our dependencies have mostly been fine about compiling using Clang on Windows (specifically the TUs that have only every been compiled on Windows).

Not at the expense of actually being able to build the product we want to build.

Totally. And I am going to hazard a guess and say Ryan didn't mean we should build only with MSVC on Windows.

My take on toolchain diversity is that we should stay away from compiler specific extensions unless absolutely necessary. This doesn't mean we should go out of our way and wire up various compilers on our buildbots. Not ensuring we build on MSVC does mean that issues may creep into the codebase that may cause problems on MSVC. But those ought to be solvable. As long as we can say that the compiler would be supported if we found a maintainer for it, thats fine by me. If however, we get to a point where we have to say that compiling with any compiler other than Clang is not possible because we ended up using Clang specific extensions, that would be unfortunate. And I don't think this has happened yet.

@stuartmorgan-g
Copy link
Contributor

That just seems like sound engineering principle to me.

I don't really see how, honestly. The toolchain is a tool; it's a means to an end. I could just as easily say "using a single build system is an anti-goal", but I suspect you wouldn't consider that an obvious engineering principle.

Also, you may want to talk to this person, who argued that we shouldn't even use different versions of the same toolchain if possible ;)

My take on toolchain diversity is that we should stay away from compiler specific extensions unless absolutely necessary.

Agreed, but AFAIK being able to do non-standard things was never an argument for switching our default to clang on Windows.

As long as we can say that the compiler would be supported if we found a maintainer for it, thats fine by me.

This patch doesn't remove support for compiling Windows with MSVC, so it doesn't seem like that was @rmacnak-google's objection.

@dnfield
Copy link
Contributor Author

dnfield commented Apr 2, 2020

I think @chinmaygarde was arguing in support of your points @stuartmorgan :)

IMO, if we provide a way for contributors to get the toolchain and build on their OS, that's a good thing. We have historically had problems where contributors without access to Windows or with only access to Windows run into trouble due to idiosyncracies of MSVC's C++ implementation. If we can remove that as a hurdle, that's a good thing. But the primary driver is still around infra support - GOMA is dropping MSVC support, and it's become incredibly flakey in the last few weeks. That slows the whole team down, particularly when we need to get something through urgently for a fix downstream.

We're not removing support for MSVC entirely, but we're no longer commiting to testing it.

That, of course, is only true if I can get this patch working again... :D

@chinmaygarde
Copy link
Contributor

@stuartmorgan: Consider that we may be in contentious agreement here. The toolchain diversity is exactly what allowed us to pull a stunt like this one. If our dependencies had mandated that their Windows TUs could only be compiled with MSVC, this patch would be hosed. Clang makes sense for us because we get to use GOMA and makes sense for Dart because the support burden is likely not significant. That is fine, everyone gets to do what suits their goals the best.

If you argue that toolchain diversity must be maintained by ensuring we use all possible compilers on our buildbots, thats not pragmatic. But no one is arguing for that. OTOH, if you argue that toolchain diversity must be maintained by ensuring we don't use Clang specific extensions, that is entirely reasonable and achievable. Viewed through this lens, I see no contention in the discussion here. In the past we had no choice but to support both toolchains, now we just need to be more careful.

@dnfield
Copy link
Contributor Author

dnfield commented Apr 3, 2020

The latest issue on this is that if I try to compile using the Windows libcxx, I get failures in BoringSSL related to https://boringssl.googlesource.com/boringssl/+/7b935937b18215294e7dbf6404742855e3349092/crypto/hrss/hrss.c#64. It looks like it's not strictly MSVC that's the issue, but the Windows libcxx implementation as well.

Unfortunately, I'm also having trouble getting things going with Clang's libcxx. I'll keep probing at that though.

@stuartmorgan-g
Copy link
Contributor

Are the issues you are seeing with clang 8? I didn't hit errors there with clang 11.

@stuartmorgan-g
Copy link
Contributor

Capturing from Discord discussion, the version I was testing with:
clang version 11.0.0 (https://github.com/llvm/llvm-project/ eaabaf7e04fe98990a8177a3e053346395efde1c)
doesn't have the boringssl issue. I can reproduce it with the (somewhat newer) version of clang that's in the PR currently.

@stuartmorgan-g
Copy link
Contributor

stuartmorgan-g commented Apr 15, 2020

Updated the PR to use the version of clang that works for me, but it looks like it's breaking the gen_snapshot build on Windows Android. I'd only tested host build locally.

@chinmaygarde
Copy link
Contributor

chinmaygarde commented Apr 18, 2020

@stuartmorgan Are you still working on this? I was able to build more targets using the Clang 11 you posted to CIPD. However, I had to adding additional warnings suppressions as well as an error where std::atomicstd::mutex* was not trivially constructible. I am attempting to work past this ATM. If you are not working on this still, I can attempt to take it to completion.

@chinmaygarde
Copy link
Contributor

chinmaygarde commented Apr 18, 2020

Nevermind, the warnings were non-fatal. I suppose it is just the atomic mutex thing.

@stuartmorgan-g
Copy link
Contributor

I was going to take another look next week to figure out what the remaining bot errors are.

Feel free to send me reviews for any fixes you make before then though.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 30, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 30, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 30, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 30, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 30, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 1, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 2, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants