Skip to content

Commit ccf3161

Browse files
authored
Update build environment and toolchains for Meson (#181)
Syntax of Meson machine files changed a lot in recent versions, this updates our cross files to keep up with the new syntax.
1 parent a78a2d9 commit ccf3161

File tree

5 files changed

+44
-31
lines changed

5 files changed

+44
-31
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BinaryBuilderBase"
22
uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e"
33
authors = ["Elliot Saba <staticfloat@gmail.com>"]
4-
version = "1.0.2"
4+
version = "1.0.3"
55

66
[deps]
77
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"

src/BuildToolchains.jl

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,29 +108,31 @@ function toolchain_file(bt::CMake, p::AbstractPlatform; is_host::Bool=false)
108108
end
109109
end
110110

111-
meson_c_args(p::AbstractPlatform) = ["'-I/workspace/destdir/include'"]
112-
meson_cxx_args(p::AbstractPlatform) = meson_c_args(p)
113-
meson_objc_args(p::AbstractPlatform) = push!(meson_c_args(p), "'-x'", "'objective-c'")
114-
meson_fortran_args(p::AbstractPlatform) = meson_c_args(p)
115-
116-
function meson_c_link_args(p::AbstractPlatform)
117-
libdir = "/workspace/destdir/" * (Sys.iswindows(p) ? "bin" : "lib")
111+
meson_c_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false) =
112+
["'-I$(envs[is_host ? "host_includedir" : "includedir"])'"]
113+
meson_cxx_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false) = meson_c_args(p, envs; is_host)
114+
meson_objc_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false) = push!(meson_c_args(p, envs; is_host), "'-x'", "'objective-c'")
115+
meson_fortran_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false) = meson_c_args(p, envs; is_host)
116+
117+
function meson_c_link_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false)
118+
prefix, libdir = envs[is_host ? "host_prefix" : "prefix"], envs[is_host ? "host_libdir" : "libdir"]
118119
if arch(p) == "powerpc64le" && Sys.islinux(p)
119-
return ["'-L$(libdir)'", "'-Wl,-rpath-link,/workspace/destdir/lib64'"]
120+
return ["'-L$(libdir)'", "'-Wl,-rpath-link,$(prefix)/lib64'"]
120121
else
121122
return ["'-L$(libdir)'"]
122123
end
123124
end
124-
meson_cxx_link_args(p::AbstractPlatform) = meson_c_link_args(p)
125-
meson_objc_link_args(p::AbstractPlatform) = meson_c_link_args(p)
126-
meson_fortran_link_args(p::AbstractPlatform) = meson_c_link_args(p)
125+
meson_cxx_link_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false) = meson_c_link_args(p, envs; is_host)
126+
meson_objc_link_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false) = meson_c_link_args(p, envs; is_host)
127+
meson_fortran_link_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false) = meson_c_link_args(p, envs; is_host)
127128

128129
# We can run native programs only if the platform matches the default host
129130
# platform, but when this is `x86_64-linux-musl` we can run executables for
130131
# * i686-linux-gnu
131132
# * x86_64-linux-gnu
132133
# * x86_64-linux-musl
133-
function meson_is_foreign(p::AbstractPlatform)
134+
function meson_is_foreign(p::AbstractPlatform; is_host::Bool=false)
135+
is_host && return "false"
134136
if platforms_match(p, default_host_platform) ||
135137
(platforms_match(default_host_platform, Platform("x86_64", "linux"; libc="musl"))
136138
&& Sys.islinux(p) && proc_family(p) == "intel" &&
@@ -165,7 +167,8 @@ function meson_cpu_family(p::AbstractPlatform)
165167
end
166168
end
167169

168-
function toolchain_file(bt::Meson, p::AbstractPlatform)
170+
function toolchain_file(bt::Meson, p::AbstractPlatform, envs::Dict{String,String};
171+
is_host::Bool=false)
169172
target = triplet(p)
170173
aatarget = aatriplet(p)
171174

@@ -181,16 +184,21 @@ function toolchain_file(bt::Meson, p::AbstractPlatform)
181184
strip = '/opt/bin/$(target)/$(aatarget)-strip'
182185
pkgconfig = '/usr/bin/pkg-config'
183186
187+
[built-in options]
188+
c_args = [$(join(meson_c_args(p, envs; is_host), ", "))]
189+
cpp_args = [$(join(meson_cxx_args(p, envs; is_host), ", "))]
190+
fortran_args = [$(join(meson_fortran_args(p, envs; is_host), ", "))]
191+
objc_args = [$(join(meson_objc_args(p, envs; is_host), ", "))]
192+
c_link_args = [$(join(meson_c_link_args(p, envs; is_host), ", "))]
193+
cpp_link_args = [$(join(meson_cxx_link_args(p, envs; is_host), ", "))]
194+
fortran_link_args = [$(join(meson_fortran_link_args(p, envs; is_host), ", "))]
195+
objc_link_args = [$(join(meson_objc_link_args(p, envs; is_host), ", "))]
196+
prefix = '$(envs[is_host ? "host_prefix" : "prefix"])'
197+
184198
[properties]
185-
c_args = [$(join(meson_c_args(p), ", "))]
186-
cpp_args = [$(join(meson_cxx_args(p), ", "))]
187-
fortran_args = [$(join(meson_fortran_args(p), ", "))]
188-
objc_args = [$(join(meson_objc_args(p), ", "))]
189-
c_link_args = [$(join(meson_c_link_args(p), ", "))]
190-
cpp_link_args = [$(join(meson_cxx_link_args(p), ", "))]
191-
fortran_link_args = [$(join(meson_fortran_link_args(p), ", "))]
192-
objc_link_args = [$(join(meson_objc_link_args(p), ", "))]
193-
needs_exe_wrapper = $(meson_is_foreign(p))
199+
needs_exe_wrapper = $(meson_is_foreign(p; is_host))
200+
cmake_toolchain_file = '$(envs[is_host ? "CMAKE_HOST_TOOLCHAIN" : "CMAKE_TARGET_TOOLCHAIN"])'
201+
cmake_defaults = false
194202
195203
[build_machine]
196204
system = 'linux'
@@ -203,13 +211,10 @@ function toolchain_file(bt::Meson, p::AbstractPlatform)
203211
cpu_family = '$(meson_cpu_family(p))'
204212
cpu = '$(meson_cpu(p))'
205213
endian = 'little'
206-
207-
[paths]
208-
prefix = '/workspace/destdir'
209214
"""
210215
end
211216

212-
function generate_toolchain_files!(platform::AbstractPlatform;
217+
function generate_toolchain_files!(platform::AbstractPlatform, envs::Dict{String,String};
213218
toolchains_path::AbstractString,
214219
host_platform::AbstractPlatform = default_host_platform,
215220
)
@@ -229,8 +234,8 @@ function generate_toolchain_files!(platform::AbstractPlatform;
229234
write(joinpath(dir, "host_$(aatriplet(p))_$(compiler).cmake"), toolchain_file(CMake{compiler}(), p; is_host=true))
230235
end
231236
end
232-
write(joinpath(dir, "$(aatriplet(p))_clang.meson"), toolchain_file(Meson{:clang}(), p))
233-
write(joinpath(dir, "$(aatriplet(p))_gcc.meson"), toolchain_file(Meson{:gcc}(), p))
237+
write(joinpath(dir, "$(aatriplet(p))_clang.meson"), toolchain_file(Meson{:clang}(), p, envs; is_host=platforms_match(p, host_platform)))
238+
write(joinpath(dir, "$(aatriplet(p))_gcc.meson"), toolchain_file(Meson{:gcc}(), p, envs; is_host=platforms_match(p, host_platform)))
234239

235240
symlink_if_exists(target, link) = ispath(joinpath(dir, target)) && symlink(target, link)
236241

src/DockerRunner.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function DockerRunner(workspace_root::String;
9393
push!(workspaces, compiler_wrapper_path => "/opt/bin")
9494

9595
# Generate CMake and Meson files
96-
generate_toolchain_files!(platform; toolchains_path=toolchains_path)
96+
generate_toolchain_files!(platform, envs; toolchains_path=toolchains_path)
9797
push!(workspaces, toolchains_path => "/opt/toolchains")
9898

9999
# the workspace_root is always a workspace, and we always mount it first

src/Runner.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,13 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
560560

561561
# Meson REQUIRES that `CC`, `CXX`, etc.. are set to the host utils. womp womp.
562562
function meson(io::IO, p::AbstractPlatform)
563+
# Ugh, we need the path to `host_prefix`, let's quickly generate our
564+
# environment variables.
565+
host_prefix = platform_envs(p, ""; host_platform=default_host_platform)["host_prefix"]
566+
563567
meson_env = Dict(
568+
# TODO: still needed? See
569+
# https://mesonbuild.com/Release-notes-for-0-54-0.html#environment-variables-with-cross-builds
564570
"AR" => "$(host_target)-ar",
565571
"CC" => "$(host_target)-cc",
566572
"CXX" => "$(host_target)-c++",
@@ -569,6 +575,8 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
569575
"NM" => "$(host_target)-nm",
570576
"OBJC" => "$(host_target)-cc",
571577
"RANLIB" => "$(host_target)-ranlib",
578+
# Needed to find pkg-config files for the host: https://mesonbuild.com/Reference-tables.html#environment-variables-per-machine
579+
"PKG_CONFIG_PATH_FOR_BUILD" => "$(host_prefix)/lib/pkgconfig:$(host_prefix)/lib64/pkgconfig:$(host_prefix)/share/pkgconfig",
572580
)
573581
wrapper(io, "/usr/bin/meson"; allow_ccache=false, env=meson_env)
574582
end

src/UserNSRunner.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function UserNSRunner(workspace_root::String;
4848
push!(workspaces, compiler_wrapper_path => "/opt/bin")
4949

5050
# Generate CMake and Meson files
51-
generate_toolchain_files!(platform; toolchains_path=toolchains_path)
51+
generate_toolchain_files!(platform, envs; toolchains_path=toolchains_path)
5252
push!(workspaces, toolchains_path => "/opt/toolchains")
5353

5454
# the workspace_root is always a workspace, and we always mount it first

0 commit comments

Comments
 (0)