Skip to content

Commit

Permalink
Babysit meson so it doesn't do the wrong thing (#352)
Browse files Browse the repository at this point in the history
it tries really hard
  • Loading branch information
gbaraldi authored Nov 10, 2023
1 parent 2181175 commit 128480c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
32 changes: 25 additions & 7 deletions src/BuildToolchains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ function cmake_os(p::AbstractPlatform)
end
end

lld_str(p::AbstractPlatform) = Sys.isapple(p) ? "ld64.lld" : "ld.lld"
function linker_string(p::AbstractPlatform, clang_use_lld)
lld_string(p::AbstractPlatform) = Sys.isapple(p) ? "ld64.lld" : "ld.lld"
function linker_string(bt::CMake{:gcc}, p::AbstractPlatform, clang_use_lld)
target = triplet(p)
aatarget = aatriplet(p)
return clang_use_lld ? "/opt/bin/$(target)/$(lld_str(p))" : "/opt/bin/$(target)/$(aatarget)-ld"
return "/opt/bin/$(target)/$(aatarget)-ld"
end

function linker_string(bt::CMake{:clang}, p::AbstractPlatform, clang_use_lld)
target = triplet(p)
aatarget = aatriplet(p)
return clang_use_lld ? "/opt/bin/$(target)/$(lld_string(p))" : "/opt/bin/$(target)/$(aatarget)-ld"
end

function toolchain_file(bt::CMake, p::AbstractPlatform, host_platform::AbstractPlatform; is_host::Bool=false, clang_use_lld::Bool=false)
Expand Down Expand Up @@ -95,7 +101,7 @@ function toolchain_file(bt::CMake, p::AbstractPlatform, host_platform::AbstractP
set(CMAKE_CXX_COMPILER /opt/bin/$(target)/$(aatarget)-$(cxx_compiler(bt)))
set(CMAKE_Fortran_COMPILER /opt/bin/$(target)/$(aatarget)-$(fortran_compiler(bt)))
set(CMAKE_LINKER $(linker_string(p, clang_use_lld)))
set(CMAKE_LINKER $(linker_string(bt, p, clang_use_lld)))
set(CMAKE_OBJCOPY /opt/bin/$(target)/$(aatarget)-objcopy)
set(CMAKE_AR /opt/bin/$(target)/$(aatarget)-ar)
Expand Down Expand Up @@ -167,6 +173,18 @@ function meson_cpu_family(p::AbstractPlatform)
end
end

function linker_string(bt::Meson{:gcc}, p::AbstractPlatform, clang_use_lld)
target = triplet(p)
aatarget = aatriplet(p)
return "bfd"
end

function linker_string(bt::Meson{:clang}, p::AbstractPlatform, clang_use_lld)
target = triplet(p)
aatarget = aatriplet(p)
return clang_use_lld ? "/opt/bin/$(target)/$(lld_string(p))" : "/opt/bin/$(target)/$(aatarget)-ld"
end

function toolchain_file(bt::Meson, p::AbstractPlatform, envs::Dict{String,String};
is_host::Bool=false, clang_use_lld::Bool=false)
target = triplet(p)
Expand All @@ -179,9 +197,9 @@ function toolchain_file(bt::Meson, p::AbstractPlatform, envs::Dict{String,String
fortran = '/opt/bin/$(target)/$(aatarget)-$(fortran_compiler(bt))'
objc = '/opt/bin/$(target)/$(aatarget)-cc'
ar = '/opt/bin/$(target)/$(aatarget)-ar'
ld = '$(linker_string(p, clang_use_lld))'
cpp_ld = '$(linker_string(p, clang_use_lld))'
c_ld = '$(linker_string(p, clang_use_lld))'
ld = '$(linker_string(bt, p, clang_use_lld))'
cpp_ld = '$(linker_string(bt, p, clang_use_lld))'
c_ld = '$(linker_string(bt, p, clang_use_lld))'
nm = '/opt/bin/$(target)/$(aatarget)-nm'
strip = '/opt/bin/$(target)/$(aatarget)-strip'
pkgconfig = '/usr/bin/pkg-config'
Expand Down
6 changes: 3 additions & 3 deletions src/Runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
return wrapper(io, "/opt/$(host_target)/bin/lld"; env=Dict("LD_LIBRARY_PATH"=>ld_library_path(platform, host_platform; csl_paths=false)), allow_ccache=false,)
function lld(io::IO, p::AbstractPlatform)
return wrapper(io,
"/opt/$(host_target)/bin/$(lld_str(p))";
"/opt/$(host_target)/bin/$(lld_string(p))";
env=Dict("LD_LIBRARY_PATH"=>ld_library_path(platform, host_platform; csl_paths=false)), allow_ccache=false,
)
end
Expand Down Expand Up @@ -877,7 +877,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
else
write_wrapper(ld, p, "ld.$(t)")
end
write_wrapper(lld,p,"$(t)-$(lld_str(p))")
write_wrapper(lld,p,"$(t)-$(lld_string(p))")
write_wrapper(lld_generic, p, "$(t)-lld")
write_wrapper(nm, p, "$(t)-nm")
write_wrapper(libtool, p, "$(t)-libtool")
Expand Down Expand Up @@ -944,7 +944,7 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
elseif Sys.iswindows(platform)
append!(default_tools, ("dlltool", "windres", "winmc"))
end
append!(default_tools, ("cc", "c++", "cpp", "f77", "gfortran", "gcc", "clang", "g++", "clang++", "lld", lld_str(platform)))
append!(default_tools, ("cc", "c++", "cpp", "f77", "gfortran", "gcc", "clang", "g++", "clang++", "lld", lld_string(platform)))
end
if :rust in compilers
append!(default_tools, ("rustc","rustup","cargo"))
Expand Down

0 comments on commit 128480c

Please sign in to comment.