JuliaPackaging / Yggdrasil

Collection of builder repositories for BinaryBuilder.jl
https://binarybuilder.org
Other
304 stars 542 forks source link

Using PETSc_jll as a dependency for other libraries #4725

Open vchuravy opened 2 years ago

vchuravy commented 2 years ago

@boriskaus is trying to use PETSc for LaMEM. This seems to work on Linux & Mac, but on windows LaMEM.dll is not loading. It complains that it can't find PETSc. I think the issue is that the internal name of PETSc is the same across the multiple libraries we load through PETSc_jll and the windows implementation of dlopen conflicts.

https://stackoverflow.com/questions/64001543/does-wl-soname-work-on-mingw-or-is-there-an-equivalent

Would be great if we could find a stable way to support PETSc_jll as a dependency.

cc: @Wimmerer @giordano @staticfloat

vchuravy commented 2 years ago

So this works for LaMEM:

using CompilerSupportLibraries_jll
using OpenBLAS32_jll
using MicrosoftMPI_jll

using Libdl

petsc_dir = "C:\\users\\vchuravy\\.julia\\artifacts\\07bd2b9204a513e590d6e8b7f2cab8e01f2bef0f"
libpetsc = joinpath(petsc_dir, "bin", "petsc", "double_real_Int32", "lib", "libpetsc_double_real_Int32.dll")

libpetsc2 = "libpetsc.dll.3.16.5"
cp(libpetsc, libpetsc2, force=true)
@show Libdl.dlopen(libpetsc2, RTLD_LAZY | RTLD_DEEPBIND)

lamem_dir = "C:\\users\\vchuravy\\.julia\\artifacts\\2d762b257c2e229fd25d5793c997f82c9089e64a"
liblamem = joinpath(lamem_dir, "bin", "LaMEMLib.dll")
@show Libdl.dlopen(liblamem, RTLD_LAZY | RTLD_DEEPBIND)

And checking the PETsc build log:

cc -L/workspace/destdir/bin  -fno-stack-protector -fPIC -O3  -L/workspace/destdir/bin -shared -fno-stack-protector -fPIC -O3 -Wl,-soname,libpetsc.dll.3.16 -o x86_64-w64-mingw32_single_complex_Int64/lib/libpetsc.dll.3.16.5 x86_64-w64-mingw32_single_complex_Int64/obj/sys/fsrc/somefort.o ...

Note the -o ../libpetsc.dll.3.16.5 which using pev:

    Library
        Name:                            libpetsc.dll.3.16.5
        Functions
            Function

So that library name got embedded. Then we move the library, but in contrast to Linux or Apple we don't change the embedded name. https://github.com/JuliaPackaging/Yggdrasil/blob/8b82958dc8bdd0e8f6ea40e2e09b57dc4d92f585/P/PETSc/build_tarballs.jl#L77

staticfloat commented 2 years ago

Unfortunately there isn't an easy way to modify PE import names. The best that I've found is machomachomangler