Commit Graph

17 Commits

Author SHA1 Message Date
Hiroshi Yamauchi
71d8118af9 Fix the clang dependency of sourcekit libraries.
Because swift_swap_compiler_if_needed updates the compiler ID to
Clang, we need to account for it when deciding to add a dependency on
clang. Otherwise, the sourcekit build could fail due to the clang
executable not having been built there yet.
2023-09-27 14:15:12 -07:00
Stéphan Kochen
7b460ce495 build: fix accidental cmake expansions
As of CMake 3.25, there are now global variables `LINUX=1`, `ANDROID=1`,
etc. These conflict with expressions that used these names as unquoted
strings in positions where CMake accepts 'variable|string', for example:

- `if(sdk STREQUAL LINUX)` would fail, because `LINUX` is now defined and
  expands to 1, where it would previously coerce to a string.

- `if(${sdk} STREQUAL "LINUX")` would fail if `sdk=LINUX`, because the
  left-hand side expands twice.

In this patch, I looked for a number of patterns to fix up, sometimes a
little defensively:

- Quoted right-hand side of `STREQUAL` where I was confident it was
  intended to be a string literal.

- Removed manual variable expansion on left-hand side of `STREQUAL`,
  `MATCHES` and `IN_LIST` where I was confident it was unintended.

Fixes #65028.
2023-07-17 21:50:50 +02:00
Alexander Smarus
4cc528d844 [cmake] Add support for external clang/clang-cl
We need an option to pass external host clang location in case
we can't use just-built clang, e.g. when we are building for
different target architecture.

Also, this adds target options for clang-cl, enabling us to
build for arm64 on Windows@amd64.
2022-01-17 16:50:06 +02:00
Alexander Smarus
8eaaace5ae cmake: Windows, adjust compiler identification on compiler swap
The latest CMake on Windows doesn't add `_CRT_USE_BUILTIN_OFFSETOF`
flag after we swap the compiler to clang-cl for targets like SourceKit. Also
`_add_host_variant_c_compile_flags` doesn't do so, because compiler
identification still points to MSVC compiler.

`_CRT_USE_BUILTIN_OFFSETOF` flag is necessary for `offsetof` calls to be
accepted as an integral constant expression.

This patch adjusts compiler identification on compiler swap and also
addresses some configuration issues related to clang-cl.
2021-12-14 18:58:41 +02:00
Saleem Abdulrasool
cca131258a Update SwiftWindowsSupport.cmake
Do not attempt to use a cross-compiled compiler for a foreign target.  This is not guaranteed to work (e.g. building for ARM on x64).  This at least surfaces the error properly.
2021-10-28 09:22:09 -07:00
Saleem Abdulrasool
a1c971907b build: repair the Windows build
This should repair the Windows build after #29451.  The quoting
behaviour was incorrect and was constructing an invalid compiler
invocation.  Solve the issue by using `target_include_directories`
instead.  However, since this needs the target, hoist the flag
computation to the local sites.  This replicates more logic because of
the custom build trying to replicate the CMake build logic in CMake.
2020-01-27 22:35:28 -08:00
Saleem Abdulrasool
33ad3befd8 build: avoid generator expression usage for compiler swap
When using the monorepo, it seems that even if Swift is built
standalone, we would see the target as imported and attempt to use the
generator expression, which would not resolve.
2019-10-20 10:41:37 -07:00
Saleem Abdulrasool
d2302fd774 build: allow unified builds on Windows
We cannot query the location of the clang target when clang is built in
a unified build.  Use a generator expression instead.
2019-10-18 13:40:38 -07:00
Saleem Abdulrasool
9b8310c3f9 build: extract compiler swap into a helper
This is needed as SwiftSyntaxParser also needs to be built with clang as
it uses blocks unconditionally.  However, building with cl provides much
better diagnostics and debugging as well as a significantly faster
build (~15-20% faster) as well as a faster compiler.
2019-03-27 15:04:49 -07:00
Nathan Lanza
c442763219 Cache VCVARS variables for incremental building on Windows
The initial configure & generate of a build on Windows should have
the necessary VCVARS set in the environment. After that, we should be
incrementally building with those same vars to avoid conflicts between
Windows SDKs.

Cache these vars so that the same Windows SDKs are consistently used
in future incremental builds.
2018-12-14 15:06:28 -08:00
Saleem Abdulrasool
c46f61c83c build: handle directories for unified build
The directory paths would collide with a cross-compiled unified build of
LLVM and swift.  Adjust the directories to work in that environment.
2018-11-03 18:14:01 -07:00
Saleem Abdulrasool
5b71e5f0f7 build: fix compatibility with VS2017 and VS2015
Adjust the build to work with the VS2017 layout while maintaining the
compatibility with VS2015.  The library location changed which results in the
link failing due to not finding system libraries.
2018-10-08 13:24:50 -07:00
Saleem Abdulrasool
decb484fac build: repair Windows build
`-ivfsoverlay` is no longer passed through to the driver with
`clang-cl`.  Explicitly mark it as a clang option to ensure that the
option is handled properly.  This repairs the build on Windows.
2018-04-23 11:20:48 -07:00
Saleem Abdulrasool
3e21e7ad9f build: canonicalise the windows paths prior to use
In order to substitute the path into the VFS overlay, we need to escape
the paths.  Instead, opt on the CMake behaviour of
`get_filename_component` providing the canonicalised path with forward
slashes rather than backslashes.  This allows the overlay to be used on
Windows as well as Linux.
2018-02-02 11:37:01 -08:00
Saleem Abdulrasool
5e4cd22e41 build: use VFS overlay for Windows SDK
The Windows SDK provides headers which have incorrect cases.  The
incorrect cases are in the SDK headers as well.  On case sensitive file
systems this causes build issues due to the incorrect name.  Use the
clang VFS overlay to avoid the need for providing copies to the expected
cases.  This improves the cross-compilation on Linux to Windows.
2017-11-03 12:50:47 -07:00
Saleem Abdulrasool
a6323fd362 build: swap include order
Visual Studio places shared above um.  Follow their ordering.
2017-10-16 16:32:51 -07:00
Saleem Abdulrasool
27d051a6c3 build: improve the Windows build infrastructure
Rather than use the `INCLUDE` and `LIB` environment variables to build
the Windows code, use the `UniversalCRTSdkDir`, `UCRTVersion`, and
`VCToolsInstallDir` variables.  Using these we can compute the right set
of include directories and library search paths for the various
architectures.  This will enable us to build multiple variants of the
Windows stdlib at the same time.

Additionally, rather than relying on the magic environment variables to
be processed by the driver, pass them explicitly to the driver through
the build system.  This also is needed to allow parallel builds of
various architecture variants of the stdlib on Windows.
2017-09-23 16:08:42 -07:00