Skip to content

Commit a0c4999

Browse files
committed
[Runner] Push /opt/${target}/${target}/lib{,64} to linker search path
When compiling with GCC this makes sure its libraries have precedence over anything else, in particular other compiler libraries that may be elsewhere, for example `CompilerSupportLibraries_jll` used as dependency during the build.
1 parent c422448 commit a0c4999

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/Runner.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,15 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
348348
end
349349

350350
function gcc_compile_flags!(p::AbstractPlatform, flags::Vector{String} = String[])
351+
if Sys.islinux(p) || Sys.isfreebsd(p)
352+
# Help GCC find its own libraries under `/opt/${target}/${target}/lib{,64}`.
353+
# Note: we need to push them directly in the wrappers before any additional
354+
# arguments because we want this path to have precedence over anything else. In
355+
# this way for example we avoid libraries from `CompilerSupportLibraries_jll` in
356+
# `${libdir}` are picked up by mistake.
357+
dir = "/opt/$(aatriplet(p))/$(aatriplet(p))/lib" * (nbits(p) == 32 ? "" : "64")
358+
append!(flags, ("-L$(dir)", "-Wl,-rpath-link,$(dir)"))
359+
end
351360
if lock_microarchitecture
352361
append!(flags, get_march_flags(arch(p), march(p), "gcc"))
353362
end

test/runners.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,41 @@ end
128128
@test endswith(readchomp(iobuff), "Hello World!")
129129
end
130130

131+
@testset "C++ - $(platform)" for platform in platforms
132+
ur = preferred_runner()(dir; platform=platform)
133+
iobuff = IOBuffer()
134+
test_c = """
135+
#include <iostream>
136+
class breakCCompiler; // Courtesy of Meson
137+
int main() {
138+
std::cout << "Hello World!" << std::endl;
139+
return 0;
140+
}
141+
"""
142+
test_script = """
143+
set -e
144+
# Install `CompilerSupportLibraries_jll` v0.5.0 in the `\${prefix}` to make
145+
# sure it doesn't break compilation of the program
146+
mkdir -p \${prefix}
147+
wget -qO - "https://github.com/JuliaBinaryWrappers/CompilerSupportLibraries_jll.jl/releases/download/CompilerSupportLibraries-v0.5.0%2B0/CompilerSupportLibraries.v0.5.0.\${target}-libgfortran3.tar.gz" | tar xzf - -C \${prefix}
148+
echo '$(test_c)' > test.cpp
149+
# Make sure we can compile successfully also when `\${libdir}` is in the
150+
# linker search path
151+
g++ -o test test.cpp -L\${libdir}
152+
./test
153+
"""
154+
cmd = `/bin/bash -c "$(test_script)"`
155+
if arch(platform) == "i686" && libc(platform) == "musl"
156+
# We can't run C++ programs for this platform
157+
@test_broken run(ur, cmd, iobuff; tee_stream=devnull)
158+
else
159+
@test run(ur, cmd, iobuff; tee_stream=devnull)
160+
seekstart(iobuff)
161+
# Test that we get the output we expect
162+
@test endswith(readchomp(iobuff), "Hello World!")
163+
end
164+
end
165+
131166
# This tests that compilers for all Intel Linux platforms can build a simple
132167
# Fortran program that we can also run
133168
@testset "Fortran - $(platform)" for platform in filter(p -> Sys.islinux(p) && proc_family(p) == "intel", supported_platforms())
@@ -140,6 +175,7 @@ end
140175
"""
141176
cmd = `/bin/bash -c "echo '$(test_f)' > test.f && gfortran -o test test.f && ./test"`
142177
if arch(platform) == "i686" && libc(platform) == "musl"
178+
# We can't run Fortran programs for this platform
143179
@test_broken run(ur, cmd, iobuff; tee_stream=devnull)
144180
else
145181
@test run(ur, cmd, iobuff; tee_stream=devnull)

0 commit comments

Comments
 (0)