{"id":6564,"date":"2015-05-01T08:54:00","date_gmt":"2015-05-01T15:54:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2015\/05\/01\/bringing-clang-to-windows\/"},"modified":"2021-10-06T14:55:28","modified_gmt":"2021-10-06T14:55:28","slug":"bringing-clang-to-windows","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/bringing-clang-to-windows\/","title":{"rendered":"Bringing Clang to Windows"},"content":{"rendered":"<p>As you may know, Visual Studio now supports <a href=\"http:\/\/blogs.msdn.com\/b\/vcblog\/archive\/2015\/04\/29\/what-s-new-with-c-cross-platform-development-with-vs-2015-rc.aspx\">building Android and iOS applications<\/a> using Clang. We realize the need of our users to write cross-platform apps and we know that C++ offers massive benefits in the cross-platform arena. Clang has made impressive strides in standards conformance and diagnostics and is fast becoming the preferred C++ compiler for non-Windows platforms. In order to extend the benefits of Clang to C++ developers building apps for Windows, we have been working on an experimental implementation of Clang on Windows. First preview of that was demonstrated in <a href=\"https:\/\/channel9.msdn.com\/events\/Build\/2015\/3-610\">this \/\/build talk by Jim Radigan<\/a>.<\/p>\n<p>The Clang and LLVM community has already done tremendous work towards providing a toolchain that builds C++ code for Windows.&nbsp; <a href=\"http:\/\/blog.llvm.org\/2013\/09\/a-path-forward-for-llvm-toolchain-on.html\">This blog post<\/a> first announced it.&nbsp; Subsequent progress was also noted through other posts such as <a href=\"http:\/\/blog.llvm.org\/2014\/07\/clangllvm-on-windows-update.html\">this<\/a> and <a href=\"http:\/\/blog.llvm.org\/2015\/01\/lldb-is-coming-to-windows.html\">this<\/a>.&nbsp; They have also provided neatly packaged <a href=\"http:\/\/llvm.org\/builds\/\">toolset builds for Windows<\/a> that integrate very nicely with Visual Studio.&nbsp; Our work builds on top of all the impressive work that the community has already done.<\/p>\n<p>On our end, the primary motivation for doing this work is to enable the cross-platform scenario where a significant portion of your app is cross-platform C++ code.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2015\/05\/7510.crossplat_code_structure.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2015\/05\/7510.crossplat_code_structure.png\" alt=\"Image 7510 crossplat code structure\" width=\"242\" height=\"318\" class=\"aligncenter size-full wp-image-29387\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2015\/05\/7510.crossplat_code_structure.png 242w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2015\/05\/7510.crossplat_code_structure-228x300.png 228w\" sizes=\"(max-width: 242px) 100vw, 242px\" \/><\/a><\/p>\n<p>If you already build cross-platform apps, you probably have a code-base that somewhat resembles the above structure. Here (1) and (3) are platform specific pieces of code, either because they call into OS-specific API or they happen to use programming language features that are provided only by some platform specific compiler tool-sets. There are usually genuine reasons for such code to exist. However, at the same time, a big chunk of your app logic is (or can be) written using proper standards conformant cross-platform C++ code. This is the block marked (2) above.<\/p>\n<p>Imagine an app whose code structure resembles the above diagram being built for various platforms:<\/p>\n<ol>\n<li>For Android and iOS, the entire apps would be built using Clang<\/li>\n<li>For Windows, the entire app would be built using Visual C++<\/li>\n<\/ol>\n<p>This essentially means that, even though we are calling the block (2) cross-platform, we are still building it using different compilers for different platforms. So, any minor divergence in features of Clang and Visual C++ will cause you as a developer to have to worry about these compiler differences or limit you to using the smallest subset of the two compiler features. This is definitely not ideal.<\/p>\n<ul>\n<li>What if you could use a single compiler for your cross-platform code irrespective of what platform you target?<\/li>\n<li>What if you could still use a separate compiler to build all of your platform specific (or compiler specific) code that you have accumulated over the years?<\/li>\n<li>What if you could have rich inter-op between the above two while still making use of the excellent, secure, debugging-friendly code-generation engine that powers Visual C++ and builds some of the most complex software on Windows (almost everything.. including Windows!)?<\/li>\n<\/ul>\n<p>This is now possible with the work we have done. What this enables is a scenario in which you compile (1) and (3) using the Visual C++ compiler, (2) using Clang and for code-generation, all of these would still use the Visual C++ back-end (We call it C2). &nbsp;All of this while still enjoying the rich end-to-end developer experience within Visual Studio.<\/p>\n<p>We believe using our back-end as the core of this technology gives us a lot of benefits since we look at C2 and the linker as a part of the ABI of the Windows platform. &nbsp;Having dealt with code-generation for all supported processor architectures under various conditions, we believe it is best placed to power the new technologies like .NET Native and now Clang (for C++ and even for ObjectiveC).<\/p>\n<p>This is work in progress and we will be talking a lot more about this work in coming months. As always, we look forward to your feedback on this scenario and our approach.<\/p>\n<p>Thank you<\/p>\n<p>Visual C++ Team<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As you may know, Visual Studio now supports building Android and iOS applications using Clang. We realize the need of our users to write cross-platform apps and we know that C++ offers massive benefits in the cross-platform arena. Clang has made impressive strides in standards conformance and diagnostics and is fast becoming the preferred C++ [&hellip;]<\/p>\n","protected":false},"author":6384,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[230],"tags":[],"class_list":["post-6564","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-new-feature"],"acf":[],"blog_post_summary":"<p>As you may know, Visual Studio now supports building Android and iOS applications using Clang. We realize the need of our users to write cross-platform apps and we know that C++ offers massive benefits in the cross-platform arena. Clang has made impressive strides in standards conformance and diagnostics and is fast becoming the preferred C++ [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/6564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/6384"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=6564"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/6564\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=6564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=6564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=6564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}