swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.66k stars 10.38k forks source link

swiftinterface compilation does not re-serialise static library builds #77756

Open hjyamauchi opened 1 week ago

hjyamauchi commented 1 week ago

Description

It seems that I recently started getting link errors related to swiftCxx.lib and swiftCxxStdlib.lib such as:

Windows (x64/arm64):

lld-link: error: could not open 'swiftCxx.lib': no such file or directory
lld-link: error: could not open 'swiftCxxStdlib.lib': no such file or directory
LINK : fatal error LNK1104: cannot open file 'swiftCxx.lib'

where I presume it should probably need to load instead libswiftCxx.lib and libswiftCxxStdlib.lib which actually exist in the toolchain directory, as opposed to swiftCxx.lib and swiftCxxStdlib.lib which don't exist there.

Locally reverting https://github.com/swiftlang/swift/pull/77559 (and https://github.com/swiftlang/swift-installer-scripts/pull/344) seems to make this error go away.

Reproduction

On a recent toolchain build in the main branch:

Windows

C:\Users\hiroshi\Test>cat Test.swift
import CXXModule

C:\Users\hiroshi\Test>cat Inputs\header.h
#ifndef HEADER_H
#define HEADER_H

#endif // HEADER_H

C:\Users\hiroshi\Test>cat Inputs\module.modulemap
module CXXModule {
  header "header.h"
  requires cplusplus
}

C:\Users\hiroshi\Test>swiftc Test.swift -cxx-interoperability-mode=default -o Test.exe -I C:\Users\hiroshi\SwiftCxxTest\Inputs
error: link command failed with exit code 1104 (use -v to see invocation)
LINK : fatal error LNK1104: cannot open file 'swiftCxx.lib'
clang: error: linker command failed with exit code 1104 (use -v to see invocation)

Expected behavior

Successful linking, no link errors.

Environment

With a recent main-branch toolchain build on windows.

Additional information

No response

hjyamauchi commented 6 days ago

CC @egorzhdan

egorzhdan commented 6 days ago

Hmm, looks like this code might need to change: https://github.com/swiftlang/swift/blob/8a78496368d579c97df381469402ee3352065091/lib/AST/ModuleDependencies.cpp#L502-L508

However, the Windows CI seems to be passing now, so I wonder if there is a difference between the CI and the local build config.

hjyamauchi commented 6 days ago

I didn't encounter this during a toolchain build, but in an internal app build. So, the Windows CI build may not trigger this particular issue. I hope that anyone other than me can reproduce with the reduced test example.

compnerd commented 6 days ago

The code doesn't need to change, it is correct. The problem is that we are building the libraries as static libraries rather than dynamic libraries, which is why they are failing to link.

compnerd commented 10 hours ago

The issue here is that we are generating a static resilient module and distributing the swiftinterface now. When the swiftinterface was being re-serialised, we would drop the static indicator resulting in the module trying to be dynamically linked when it was static.