Skip to content

[Runner] Push /opt/${target}/${target}/lib{,64} to linker search path #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>"]
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