Repository navigation
fix(msvc): let the archiver find Ole32.lib and other objects given by name - #2114
Merged
Merged
Conversation
…by name
Since cc runs `lib.exe` and `llvm-lib` in the output directory, a relative
object that isn't under it is passed by its absolute path from the current
directory. A name that only the archiver can find, such as
`.object("Ole32.lib")`, which `lib.exe` used to find along `LIB`, then
became a path in the build script's folder that doesn't exist, and the
archiver failed with LNK1181.
Make a relative object absolute only when it exists from the current
directory. Any other name is passed as given, and the archiver looks for it
in the output directory and then along `LIB`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since cc 1.9.0, build scripts that pass a system library by name through
Build::objectfail on MSVC targets:directxtex 1.3.0 does this (build.rs), and JorisJonkers-dev/ttwright-rs holds cc below 1.9 because of it (#34, #48). escapi 4.0.0 passes eight system libraries the same way (build.rs).
Up to 1.8.0, cc ran
lib.exein the build script's current directory, the package folder, and passed such a name as given.lib.exeandllvm-liblook for an input in the current directory and then alongLIB, which cc sets when it finds the MSVC tools, so they found the SDK'sOle32.liband added its import members to the library. #2033 runs the archiver in the output directory, so member names don't contain the build path, and passes a relative object from elsewhere by its absolute path so the archiver still finds it. For a name likeOle32.libthat path doesn't exist.This makes a relative object absolute only when it exists from the current directory. Any other name is passed as given, and the archiver looks for it in the output directory and then along
LIB. Compared with 1.8.0, the only new place is the output directory, searched beforeLIB. The rest of #2033 stays: objects cc compiles are passed relative to the output directory, an existing relative object is passed by its absolute path, andARFLAGS,ar_flagand arguments inARkeep the current directory.ar,llvm-arand libtool are unchanged.cargo:rustc-link-lib=ole32is the usual way to link a system library, butlib.exetakes existing libraries as inputs and these builds worked up to 1.8.0. Withlib.exeandllvm-lib, only builds that fail today change: since 1.9.0 such a name reached the archiver as a path to a missing file.Testing:
msvc_archive_passes_unknown_names_as_givenchecks thatOle32.libandmissing/foo.objreach the archiver as given while it runs inOUT_DIR. It fails on main.Cargo.toml, which exists from the current directory, so they still check that an existing relative object is passed by its absolute path.lib.exeand the build script above. cc 1.8.0 builds, 1.9.0 and 1.11.3 fail with LNK1181, and this branch builds. The binary callsCoInitializeExthrough the library without arustc-link-lib=ole32line.lib.exe /listshows1d1ea73a2512983e-com.oand theole32.dllimport members, so the archive still holds no build path.lib.exeand LLVM's lib driver (run asrust-lld -flavor link /lib) both find a bare name and a relative path with a folder alongLIB.