Skip to content
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

[Bug] “DependenciesTestObserver” fails to build with the Swift 6.0 musl-based static SDK #331

Open
2 of 3 tasks
Andrewangeta opened this issue Jan 27, 2025 · 3 comments

Comments

@Andrewangeta
Copy link
Contributor

Description

Overview

When building swift-dependencies on a musl-based Linux environment (i.e., using the Swift Static Linux SDK for full static linking), we encounter build failures around DependenciesTestObserver and XCTest. The new static SDK includes a musl variant (--swift-sdk x86_64-swift-linux-musl), but references to XCTest (and dynamic linking logic) in DependenciesTestObserver cause compile errors:
no such module 'XCTest' and

import Glibc
28.17     |          `- error: no such module 'Glibc'

Generally the guides suggest adding the import conditional vs os check

#if os(macOS) || os(iOS)
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import ucrt
#else
#error(Unknown platform)
#endif

But I'm unclear of all the context of the runtime checks in those utilities and the package manifest conditionals as well.

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

Successful compilation

Actual behavior

Failed compilation

Steps to reproduce

  1. Create a Dockerfile (for example) that uses Swift 6.0.3’s Static Linux SDK and musl target. Here’s a minimal snippet:
FROM swiftlang/swift:6.0-noble AS build

ARG STATIC_SDK_URL="https://download.swift.org/swift-6.0.3-release/static-sdk/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz"
ARG STATIC_SDK_CHECKSUM="67765e0030e661a745967e4877cfe088db45f7177d5a98a0e26fd661cdd0bd"

# Install the musl-based static SDK
RUN swift sdk install $STATIC_SDK_URL --checksum $STATIC_SDK_CHECKSUM

WORKDIR /app
COPY . .

# Attempt to build just the "Dependencies" product:
RUN swift build \
  --configuration release \
  --swift-sdk x86_64-swift-linux-musl \
  --product Dependencies

# ...
  1. Build and observe build failure output. docker build -t dependencies-musl-test .

Dependencies version information

1.6.3

Destination operating system

linux

Xcode version information

16.2

Swift Compiler version information

See Dockerfile
@Andrewangeta Andrewangeta added the bug Something isn't working label Jan 27, 2025
@stephencelis
Copy link
Member

@Andrewangeta Can you attach a project that reproduces the issue for easier debugging?

@Andrewangeta
Copy link
Contributor Author

@stephencelis For some reason GitHub won't let me upload the zip file no matter what I do.

@Andrewangeta
Copy link
Contributor Author

@stephencelis
Oops, I compressed the build folder so it was a large attachment.
Just run docker build -t musl-demo . in the root.
musl-demo.zip

@mbrandonw mbrandonw removed the bug Something isn't working label Feb 4, 2025
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

No branches or pull requests

3 participants