Registry Mirror
Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

Conversation

@compnerd

Copy link
Copy Markdown
Contributor

We cannot simply explicitly spell out the linked library name in
general. On Windows, the name of the library is determined by the
library in use and selects across the following matrix:

Debug Release
Static libxml2sd.lib libxml2s.lib
Dynamic xml2d.lib xml2.lib

Note that this already assumes that the dynamic MSVC library (/MD)
build is in use. The selection between /MD and /MT is not something
that can be identified by the name.

Accommodating this within the modulemap is not entirely reasonable. As
a result, in order to maintain compatibility with the current behaviour,
I've resorted to some module level inline assembly (simply to avoid
adding a source file as there is no source file currently for the
module). By hand constructing the linker directives for Linux and
macOS, we can continue to have the autolinking behaviour which can
support all the platforms.

The alternative to all this mess would be to require the user to specify
the location of the import library, DSO, or TBD (depending on the
platform) manually when invoking the swift build tool.

We cannot simply explicitly spell out the linked library name in
general.  On Windows, the name of the library is determined by the
library in use and selects across the following matrix:

| | Debug | Release |
| --- | --- | --- |
| **Static** | `libxml2sd.lib` | `libxml2s.lib` |
| **Dynamic** | `xml2d.lib` | `xml2.lib` |

Note that this already assumes that the dynamic MSVC library (`/MD`)
build is in use.  The selection between `/MD` and `/MT` is not something
that can be identified by the name.

Accommodating this within the modulemap is not entirely reasonable.  As
a result, in order to maintain compatibility with the current behaviour,
I've resorted to some module level inline assembly (simply to avoid
adding a source file as there is no source file currently for the
module).  By hand constructing the linker directives for Linux and
macOS, we can continue to have the autolinking behaviour which can
support all the platforms.

The alternative to all this mess would be to require the user to specify
the location of the import library, DSO, or TBD (depending on the
platform) manually when invoking the swift build tool.
@mattt

mattt commented Apr 26, 2021

Copy link
Copy Markdown
Contributor

Goodness. That's, um... much more involved than I expected. Kudos for finding a solution that works at all. And again, apologies on my end for deciding to pull in a notoriously challenging dependency for swift-doc. On the plus side, I'm learning a lot from all of your changes, and I'm looking forward to writing to give this more visibility to anyone else who'd benefit from this information.

@mattt
mattt merged commit 0bf4e15 into SwiftDocOrg:main Apr 26, 2021
@mattt

mattt commented Apr 26, 2021

Copy link
Copy Markdown
Contributor

#6 and #5 are now available in version 0.1.2

@compnerd
compnerd deleted the autolinking branch April 27, 2021 02:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants