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 authored and staticfloat committed Jul 12, 2021
1 parent c422448 commit 13dc99e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BinaryBuilderBase"
uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e"
authors = ["Elliot Saba <staticfloat@gmail.com>"]
version = "0.6.11"
version = "0.6.12"

[deps]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
Expand Down
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 GCCBootstrap 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
74 changes: 66 additions & 8 deletions test/runners.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Test
using BinaryBuilderBase
using BinaryBuilderBase: platform_dlext, platform_exeext
using Pkg

@testset "Wrappers utilities" begin
@test nbits(Platform("i686", "linux")) == 32
Expand Down Expand Up @@ -105,13 +106,13 @@ end
end
end

# This tests that compilers for all Intel Linux platforms can build a simple
# C program that we can also run
# This tests that compilers for all Intel Linux platforms can build simple
# C, C++, Fortran programs that we can also run
@testset "Compilation and running" begin
mktempdir() do dir
platforms = filter(p -> Sys.islinux(p) && proc_family(p) == "intel", supported_platforms())
platforms = filter(p -> Sys.islinux(p) && proc_family(p) == "intel", supported_platforms())

@testset "C - $(platform)" for platform in platforms
@testset "C - $(platform)" for platform in platforms
mktempdir() do dir
ur = preferred_runner()(dir; platform=platform)
iobuff = IOBuffer()
test_c = """
Expand All @@ -127,10 +128,66 @@ end
# Test that we get the output we expect
@test endswith(readchomp(iobuff), "Hello World!")
end
end

@testset "C++ - $(platform)" for platform in platforms
mktempdir() do dir
# Use an old GCC with libgfortran3
options = (preferred_gcc_version=v"4", compilers=[:c])
shards = choose_shards(platform; options...)
concrete_platform = get_concrete_platform(platform, shards)
prefix = setup_workspace(
dir,
[],
concrete_platform,
default_host_platform;
)
# Install `CompilerSupportLibraries_jll` v0.5.0 in the `${prefix}` to make
# sure it doesn't break compilation of the program for i686-linux-gnu, see
# https://github.com/JuliaPackaging/BinaryBuilderBase.jl/issues/163
artifact_paths =
setup_dependencies(prefix,
[PackageSpec(; name="CompilerSupportLibraries_jll", version="0.5.0")],
concrete_platform, verbose=false)
ur = preferred_runner()(prefix.path;
platform=concrete_platform,
shards = shards,
options...)
iobuff = IOBuffer()
test_cpp = """
#include <iostream>
class breakCCompiler; // Courtesy of Meson
int main() {
std::cout << "Hello World!" << std::endl;
return 0;
}
"""
test_script = """
set -e
echo '$(test_cpp)' > 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
cleanup_dependencies(prefix, artifact_paths, concrete_platform)
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())
# 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 platforms
mktempdir() do dir
ur = preferred_runner()(dir; platform=platform)
iobuff = IOBuffer()
test_f = """
Expand All @@ -140,6 +197,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

2 comments on commit 13dc99e

@giordano
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/40768

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.12 -m "<description of version>" 13dc99e2fe08336f4b8e583626f9183722a4d8a9
git push origin v0.6.12

Please sign in to comment.