Skip to content

[CMake] Get SwiftCore building with the new build system #77403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Nov 7, 2024

Conversation

etcwilde
Copy link
Member

@etcwilde etcwilde commented Nov 5, 2024

This PR gets us up to SwiftCore building with the new build system.
I've wired it into the existing build and am enabling building with it in the Linux smoke-tests to keep things going. We are not currently running or installing the built code though.

rdar://139221398

This patch gets the LLVM Support object files building.
@etcwilde
Copy link
Member Author

etcwilde commented Nov 5, 2024

@swift-ci please smoke test

@etcwilde
Copy link
Member Author

etcwilde commented Nov 5, 2024

Linux test failure:

CMake Error at CMakeLists.txt:32 (cmake_minimum_required):
  CMake 3.26 or higher is required.  You are running version 3.24.2

@etcwilde
Copy link
Member Author

etcwilde commented Nov 5, 2024

We'll need to update our CMake version

# functionality. When building the demangling library, the macro should be set
# to 0 or 1 to indicate the presence of the crashreporter.
# When building the runtime library, the existence of the macro indicates the
# presence of the crashreporter.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we set it to 1 when enabled and un-set it when disabled? That should work for both.

Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I can tell, C/C++ defines it so that if a -DFOO is passed without a value, it's given the value of 1, and #if FOO will see undefined an 0 the same way. We might be able to get away with just setting it. I'll have to compare the symbol lists though.

@@ -0,0 +1 @@
__SIZEOF_POINTER__
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be gitignored? Looks like PlatformInfo.cmake writes this when it's needed. Or maybe PlatformInfo.cmake doesn't need to write it.

Copy link
Member

Choose a reason for hiding this comment

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

This file is explicitly used in PlatformInfo.cmake below.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, but it's also created there:

  file(WRITE ${CMAKE_BINARY_DIR}/cmake/CompilerChecks/ptr_size "__SIZEOF_POINTER__")
  set(size_check_command ${CMAKE_C_COMPILER} -x c -P -E -o - ${CMAKE_BINARY_DIR}/cmake/CompilerChecks/ptr_size)

I'm thinking it should be committed, or written when needed, but probably not both.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this file isn't necessary. Since we have C enabled, I can probably just use CMAKE_SIZEOF_VOID_P and skip this. I was having some issues with it before where it was empty/wrong with older versions of CMake, but it looks like it's behaving correctly now.

@@ -0,0 +1,41 @@
# FIXME: Refactor demangling library so that we aren't pulling sources from
Copy link
Member

Choose a reason for hiding this comment

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

Can we reference a swiftlang/swift issue here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add it in a separate PR, but here's the issue: #77462

@etcwilde etcwilde force-pushed the ewilde/stdlib-rebuild-swiftcore branch 2 times, most recently from 23f8201 to 02280ba Compare November 6, 2024 23:58
@etcwilde
Copy link
Member Author

etcwilde commented Nov 6, 2024

@swift-ci please test

Getting the runtime libraries building, while also ironing out more of
the macro definitions and flags.
Adding stdlib stubs library, which uses gyb and requires knowing about
some of the platform info.

The stubs library pulls in several headers from the compiler repository.
We should probably clean that up, but not right now. I've made a note of
it.
This patch hooks up the swiftCore library build and gets it installing.
This means that we have library evolution hooked up and vector types.

Building it dynamically found that we had duplicate symbols, so fixed
the swiftDemanglingCR library.

Needed to hook up the availability macros.

The flag configuration is for macOS, so we'll need to go through and
figure out what it should look like for the other platforms too.
This patch makes it simpler to setup reasonable defaults for a given
platform. The standard library has many knobs for configuration
purposes. This is great for providing cache files to configure specific
builds, but the build system should still generally work if someone runs
a minimal CMake invocation against the build without futzing with
various options.
Setting `SWIFT_ENABLE_NEW_RUNTIME_BUILD` to `ON` will build and run the
new standard library build in addition to using the old build. This is
primarily for basic smoke testing at the moment. Once we're confident,
we can start running tests against the stdlib built with the new
build system.

The mechanism will build the stdlib for each of the same platforms that
the old build system would build for, but emitting a separate build
directory with a separate CMake invocation for each configuration.

This will use the just-built compiler if the compiler was not
cross-compiled. If the compiler were cross-compiled, it will use the
compiler from the toolchain that is known to work on the builder.
Moving the rest of the references to the compiler source directory to
use the `SwiftCore_SWIFTC_SOURCE_DIR` variable instead of
`${PROJECT_SOURCE_DIR}/../../`.
Fixing some of the comments in DefaultSettings.cmake and
PlatformInfo.cmake.

I haven't added any vendor cache files yet, so the comment doesn't point
anywhere. Also fixing the reference to the location of the clang
resource headers in PlatformInfo.cmake.
This patch causes the convenient flow to automatically populate the
sources into the new runtime directory layout. This is run at build-time
so that it repopulates on each build. Since the resync script uses
`COPY_IF_DIFFERENT`, only files that change in the main source directory
are copied over, so incremental builds should still work.

Fixed a small bug in the resync script to ensure that it creates the
subdirectories in the right places.
De-duping some of the definitions. We can pass most of the definitions
to both the Swift and C/C++ compilers in the same form if we don't
assign anything. C/C++ will set the macro value to `1` if there is no
`=` as part of the definition, and `#if` recognizes a non-existent macro
to be false. With this logic, we can unify some of these.
@etcwilde etcwilde force-pushed the ewilde/stdlib-rebuild-swiftcore branch from 02280ba to dad1ea8 Compare November 7, 2024 05:29
@etcwilde
Copy link
Member Author

etcwilde commented Nov 7, 2024

@swift-ci please smoke test

@etcwilde etcwilde requested a review from compnerd November 7, 2024 05:32
This patch cleans up the handling of WMO-forcing in the workaround file.
`-wmo` is passed in each of the link jobs in the non-CMP0157-enabled
configuration to keep it matching the behavior of the CMP0157-enabled
builds.

This also moves the commentary about num-threads and WMO to the top of
the file to make it clearer what is going on. Ideally the file wouldn't
have to exist, but it does.

The file also contains the target install-name fix that landed in CMake
3.29.8 and CMake 3.30.2, so earlier versions of CMake 3.29 will work
with this build as well.
The SwiftCore_SWIFTC_CLANGIMPORTER_RESOURCE_DIR is not being used so I'm
deleting it for now. This means we only grab the target info once.
@etcwilde
Copy link
Member Author

etcwilde commented Nov 7, 2024

@swift-ci please smoke test

@etcwilde
Copy link
Member Author

etcwilde commented Nov 7, 2024

@swift-ci please test Linux

@etcwilde etcwilde merged commit e54bcef into swiftlang:main Nov 7, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants