Skip to content

Add CMake build support - #96

Closed
rksharma-owg wants to merge 7 commits into
apple:mainfrom
rksharma-owg:codex/context-86-cmake
Closed

rksharma-owg wants to merge 7 commits into
apple:mainfrom
rksharma-owg:codex/context-86-cmake

Conversation

@rksharma-owg

Copy link
Copy Markdown

The package cannot currently be built by a CMake consumer because it has no CMake entry point. This adds the library targets described in Package.swift, build-tree and relocatable installed package exports, and an independent consumer that imports and exercises both public modules.

The build supports Swift 6.2+ and CMake 3.29+ with Ninja; Ninja Multi-Config requires CMake 4.0+. Build instructions cover the required Windows developer environment. On Windows, InstrumentationBaggage stays static in shared builds because its re-exports/type aliases produce no DLL import library. ServiceContextModule follows BUILD_SHARED_LIBS. Runtime Swift source and Package.swift are unchanged.

Validation:

  • macOS and Linux: static/shared libraries, Ninja and Ninja Multi-Config, build-tree and relocated-install consumers.
  • Strict SwiftPM test suite: 10 tests passed locally on Linux Swift 6.4.
  • Minimum CMake 3.29.6 consumer checked on Linux.
  • Full fork preflight: all 51 enabled jobs passed against 9a54f53, including the upstream unit/build, API, documentation, formatting, license, C++ interoperability, benchmark, SDK and compiler checks configured for this package. Upstream configuration disables the macOS documentation job; it is N/A, not a pass.
  • Additional Windows CMake checks: Swift 6.2 and 6.3 passed; Swift 6.4 passed in the full run. Each compiler runs eight static/shared, single/multi-config, build-tree/relocated consumer checks. No CRT-conflict warnings remain in those logs.

This targets current main. The pending ServiceContext move in #92 changes the dependency direction and would require adapting the CMake graph when merged.

Closes #86.

**Motivation:**

Swift Service Context has no CMake build, preventing CMake-based consumers from building its libraries (apple#86).

**Modifications:**

Add explicit module targets, Swift package compilation settings, build-tree and relocatable install exports, and independent consumer tests with build documentation. Preserve SwiftPM and the runtime source.

**Result:**

CMake consumers can build, import, link, and run against static or shared libraries. Local macOS and Linux Swift 6.4 tests cover Ninja and Ninja Multi-Config and moved installation prefixes.
**Motivation:**

The required license check expects the complete project header. Generic helper names can also collide in CMake superbuilds.

**Modifications:**

Add the required headers and scope helper names to their package.

**Result:**

The upstream license script passes locally, and static/shared Ninja and Ninja Multi-Config builds with build-tree and relocated consumers pass on macOS and Linux.
**Motivation:**

The Windows consumer test cannot link because Swift requests lib-prefixed libraries while CMake emits unprefixed MSVC library names.

**Modifications:**

Use the lib prefix for Windows libraries and import libraries. Document the Visual Studio developer environment required for standalone compiler/linker invocations.

**Result:**

CMake output names match Swift autolink requests. The existing Windows consumer is the regression check; its cloud rerun is pending. The macOS superbuild consumer and license checks pass locally.
**Motivation:**

CMake's MSVC C backend initializes shared linker flags that Swift cannot consume directly. The real Windows shared-library build fails before linking its consumer.

**Modifications:**

Document Clang's GNU-style C driver for Windows configuration and report unsupported shared-driver combinations early. Give the consumer the same C/Swift platform initialization as the libraries and clarify its dependency prefix example.

**Result:**

Windows configuration uses Swift-compatible linker conventions without dropping linker checks. Static/shared macOS consumers pass; Windows shared validation is pending.
**Motivation:**

The real shared-library test shows that Swift requests ServiceContextModule.lib for DLL imports, while static imports require libServiceContextModule.lib. Applying the prefix to both forms prevents the dependent DLL from linking.

**Modifications:**

Apply the lib prefix only to Windows static library targets. Keep native shared-library and import-library names.

**Result:**

Target names match the distinct Swift autolink conventions. Static Windows consumers already passed; shared Windows validation of this correction is pending.
**Motivation:**

Hosted consumer tests pass but report conflicting CRT defaults. CMake selects the debug CRT for Debug configurations while the Swift SDK uses the release DLL CRT.

**Modifications:**

Default Windows library and consumer targets to MultiThreadedDLL unless callers explicitly choose a runtime. Document the matching setting for independent consumers.

**Result:**

Debug and release configurations select the SDK-compatible CRT without suppressing linker diagnostics. The existing hosted consumer tests will validate the Windows correction; Unix configure/build checks pass.
@kukushechkin

Copy link
Copy Markdown
Contributor

@rksharma-owg thank you for the PR! I would recommend waiting for the #92 to be merged, because it changes repo structure significantly. I also think after that we no longer need CMake support, as SDT no longer depends on it.

@kukushechkin

Copy link
Copy Markdown
Contributor

Most of the SSC content has been moved to the SDT and this is now a thin backward compatibility package. No need to add CMake build for it.

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.

Support building with CMake

2 participants