Skip to content

Commit

Permalink
[Runner] Push /opt/${target}/${target}/lib{,64} to linker search path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
giordano committed Jul 10, 2021
1 parent c422448 commit a0c4999
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,15 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
end

function gcc_compile_flags!(p::AbstractPlatform, flags::Vector{String} = String[])
if Sys.islinux(p) || Sys.isfreebsd(p)
# Help GCC find its own libraries under `/opt/${target}/${target}/lib{,64}`.
# Note: we need to push them directly in the wrappers before any additional
# arguments because we want this path to have precedence over anything else. In
# this way for example we avoid libraries from `CompilerSupportLibraries_jll` in
# `${libdir}` are picked up by mistake.
dir = "/opt/$(aatriplet(p))/$(aatriplet(p))/lib" * (nbits(p) == 32 ? "" : "64")
append!(flags, ("-L$(dir)", "-Wl,-rpath-link,$(dir)"))
end
if lock_microarchitecture
append!(flags, get_march_flags(arch(p), march(p), "gcc"))
end
Expand Down
36 changes: 36 additions & 0 deletions test/runners.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,41 @@ end
@test endswith(readchomp(iobuff), "Hello World!")
end

@testset "C++ - $(platform)" for platform in platforms
ur = preferred_runner()(dir; platform=platform)
iobuff = IOBuffer()
test_c = """
#include <iostream>
class breakCCompiler; // Courtesy of Meson
int main() {
std::cout << "Hello World!" << std::endl;
return 0;
}
"""
test_script = """
set -e
# Install `CompilerSupportLibraries_jll` v0.5.0 in the `\${prefix}` to make
# sure it doesn't break compilation of the program
mkdir -p \${prefix}
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}
echo '$(test_c)' > test.cpp
# Make sure we can compile successfully also when `\${libdir}` is in the
# linker search path
g++ -o test test.cpp -L\${libdir}
./test
"""
cmd = `/bin/bash -c "$(test_script)"`
if arch(platform) == "i686" && libc(platform) == "musl"
# We can't run C++ programs for this platform
@test_broken run(ur, cmd, iobuff; tee_stream=devnull)
else
@test run(ur, cmd, iobuff; tee_stream=devnull)
seekstart(iobuff)
# Test that we get the output we expect
@test endswith(readchomp(iobuff), "Hello World!")
end
end

# This tests that compilers for all Intel Linux platforms can build a simple
# Fortran program that we can also run
@testset "Fortran - $(platform)" for platform in filter(p -> Sys.islinux(p) && proc_family(p) == "intel", supported_platforms())
Expand All @@ -140,6 +175,7 @@ end
"""
cmd = `/bin/bash -c "echo '$(test_f)' > test.f && gfortran -o test test.f && ./test"`
if arch(platform) == "i686" && libc(platform) == "musl"
# We can't run Fortran programs for this platform
@test_broken run(ur, cmd, iobuff; tee_stream=devnull)
else
@test run(ur, cmd, iobuff; tee_stream=devnull)
Expand Down

0 comments on commit a0c4999

Please sign in to comment.