Skip to content

Commit

Permalink
Update build environment and toolchains for Meson (#181)
Browse files Browse the repository at this point in the history
Syntax of Meson machine files changed a lot in recent versions, this updates our
cross files to keep up with the new syntax.
  • Loading branch information
giordano authored Nov 21, 2021
1 parent a78a2d9 commit ccf3161
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 31 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 = "1.0.2"
version = "1.0.3"

[deps]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
Expand Down
61 changes: 33 additions & 28 deletions src/BuildToolchains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,31 @@ function toolchain_file(bt::CMake, p::AbstractPlatform; is_host::Bool=false)
end
end

meson_c_args(p::AbstractPlatform) = ["'-I/workspace/destdir/include'"]
meson_cxx_args(p::AbstractPlatform) = meson_c_args(p)
meson_objc_args(p::AbstractPlatform) = push!(meson_c_args(p), "'-x'", "'objective-c'")
meson_fortran_args(p::AbstractPlatform) = meson_c_args(p)

function meson_c_link_args(p::AbstractPlatform)
libdir = "/workspace/destdir/" * (Sys.iswindows(p) ? "bin" : "lib")
meson_c_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false) =
["'-I$(envs[is_host ? "host_includedir" : "includedir"])'"]
meson_cxx_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false) = meson_c_args(p, envs; is_host)
meson_objc_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false) = push!(meson_c_args(p, envs; is_host), "'-x'", "'objective-c'")
meson_fortran_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false) = meson_c_args(p, envs; is_host)

function meson_c_link_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false)
prefix, libdir = envs[is_host ? "host_prefix" : "prefix"], envs[is_host ? "host_libdir" : "libdir"]
if arch(p) == "powerpc64le" && Sys.islinux(p)
return ["'-L$(libdir)'", "'-Wl,-rpath-link,/workspace/destdir/lib64'"]
return ["'-L$(libdir)'", "'-Wl,-rpath-link,$(prefix)/lib64'"]
else
return ["'-L$(libdir)'"]
end
end
meson_cxx_link_args(p::AbstractPlatform) = meson_c_link_args(p)
meson_objc_link_args(p::AbstractPlatform) = meson_c_link_args(p)
meson_fortran_link_args(p::AbstractPlatform) = meson_c_link_args(p)
meson_cxx_link_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false) = meson_c_link_args(p, envs; is_host)
meson_objc_link_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false) = meson_c_link_args(p, envs; is_host)
meson_fortran_link_args(p::AbstractPlatform, envs::Dict{String,String}; is_host::Bool=false) = meson_c_link_args(p, envs; is_host)

# We can run native programs only if the platform matches the default host
# platform, but when this is `x86_64-linux-musl` we can run executables for
# * i686-linux-gnu
# * x86_64-linux-gnu
# * x86_64-linux-musl
function meson_is_foreign(p::AbstractPlatform)
function meson_is_foreign(p::AbstractPlatform; is_host::Bool=false)
is_host && return "false"
if platforms_match(p, default_host_platform) ||
(platforms_match(default_host_platform, Platform("x86_64", "linux"; libc="musl"))
&& Sys.islinux(p) && proc_family(p) == "intel" &&
Expand Down Expand Up @@ -165,7 +167,8 @@ function meson_cpu_family(p::AbstractPlatform)
end
end

function toolchain_file(bt::Meson, p::AbstractPlatform)
function toolchain_file(bt::Meson, p::AbstractPlatform, envs::Dict{String,String};
is_host::Bool=false)
target = triplet(p)
aatarget = aatriplet(p)

Expand All @@ -181,16 +184,21 @@ function toolchain_file(bt::Meson, p::AbstractPlatform)
strip = '/opt/bin/$(target)/$(aatarget)-strip'
pkgconfig = '/usr/bin/pkg-config'
[built-in options]
c_args = [$(join(meson_c_args(p, envs; is_host), ", "))]
cpp_args = [$(join(meson_cxx_args(p, envs; is_host), ", "))]
fortran_args = [$(join(meson_fortran_args(p, envs; is_host), ", "))]
objc_args = [$(join(meson_objc_args(p, envs; is_host), ", "))]
c_link_args = [$(join(meson_c_link_args(p, envs; is_host), ", "))]
cpp_link_args = [$(join(meson_cxx_link_args(p, envs; is_host), ", "))]
fortran_link_args = [$(join(meson_fortran_link_args(p, envs; is_host), ", "))]
objc_link_args = [$(join(meson_objc_link_args(p, envs; is_host), ", "))]
prefix = '$(envs[is_host ? "host_prefix" : "prefix"])'
[properties]
c_args = [$(join(meson_c_args(p), ", "))]
cpp_args = [$(join(meson_cxx_args(p), ", "))]
fortran_args = [$(join(meson_fortran_args(p), ", "))]
objc_args = [$(join(meson_objc_args(p), ", "))]
c_link_args = [$(join(meson_c_link_args(p), ", "))]
cpp_link_args = [$(join(meson_cxx_link_args(p), ", "))]
fortran_link_args = [$(join(meson_fortran_link_args(p), ", "))]
objc_link_args = [$(join(meson_objc_link_args(p), ", "))]
needs_exe_wrapper = $(meson_is_foreign(p))
needs_exe_wrapper = $(meson_is_foreign(p; is_host))
cmake_toolchain_file = '$(envs[is_host ? "CMAKE_HOST_TOOLCHAIN" : "CMAKE_TARGET_TOOLCHAIN"])'
cmake_defaults = false
[build_machine]
system = 'linux'
Expand All @@ -203,13 +211,10 @@ function toolchain_file(bt::Meson, p::AbstractPlatform)
cpu_family = '$(meson_cpu_family(p))'
cpu = '$(meson_cpu(p))'
endian = 'little'
[paths]
prefix = '/workspace/destdir'
"""
end

function generate_toolchain_files!(platform::AbstractPlatform;
function generate_toolchain_files!(platform::AbstractPlatform, envs::Dict{String,String};
toolchains_path::AbstractString,
host_platform::AbstractPlatform = default_host_platform,
)
Expand All @@ -229,8 +234,8 @@ function generate_toolchain_files!(platform::AbstractPlatform;
write(joinpath(dir, "host_$(aatriplet(p))_$(compiler).cmake"), toolchain_file(CMake{compiler}(), p; is_host=true))
end
end
write(joinpath(dir, "$(aatriplet(p))_clang.meson"), toolchain_file(Meson{:clang}(), p))
write(joinpath(dir, "$(aatriplet(p))_gcc.meson"), toolchain_file(Meson{:gcc}(), p))
write(joinpath(dir, "$(aatriplet(p))_clang.meson"), toolchain_file(Meson{:clang}(), p, envs; is_host=platforms_match(p, host_platform)))
write(joinpath(dir, "$(aatriplet(p))_gcc.meson"), toolchain_file(Meson{:gcc}(), p, envs; is_host=platforms_match(p, host_platform)))

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

Expand Down
2 changes: 1 addition & 1 deletion src/DockerRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function DockerRunner(workspace_root::String;
push!(workspaces, compiler_wrapper_path => "/opt/bin")

# Generate CMake and Meson files
generate_toolchain_files!(platform; toolchains_path=toolchains_path)
generate_toolchain_files!(platform, envs; toolchains_path=toolchains_path)
push!(workspaces, toolchains_path => "/opt/toolchains")

# the workspace_root is always a workspace, and we always mount it first
Expand Down
8 changes: 8 additions & 0 deletions src/Runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,13 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr

# Meson REQUIRES that `CC`, `CXX`, etc.. are set to the host utils. womp womp.
function meson(io::IO, p::AbstractPlatform)
# Ugh, we need the path to `host_prefix`, let's quickly generate our
# environment variables.
host_prefix = platform_envs(p, ""; host_platform=default_host_platform)["host_prefix"]

meson_env = Dict(
# TODO: still needed? See
# https://mesonbuild.com/Release-notes-for-0-54-0.html#environment-variables-with-cross-builds
"AR" => "$(host_target)-ar",
"CC" => "$(host_target)-cc",
"CXX" => "$(host_target)-c++",
Expand All @@ -569,6 +575,8 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
"NM" => "$(host_target)-nm",
"OBJC" => "$(host_target)-cc",
"RANLIB" => "$(host_target)-ranlib",
# Needed to find pkg-config files for the host: https://mesonbuild.com/Reference-tables.html#environment-variables-per-machine
"PKG_CONFIG_PATH_FOR_BUILD" => "$(host_prefix)/lib/pkgconfig:$(host_prefix)/lib64/pkgconfig:$(host_prefix)/share/pkgconfig",
)
wrapper(io, "/usr/bin/meson"; allow_ccache=false, env=meson_env)
end
Expand Down
2 changes: 1 addition & 1 deletion src/UserNSRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function UserNSRunner(workspace_root::String;
push!(workspaces, compiler_wrapper_path => "/opt/bin")

# Generate CMake and Meson files
generate_toolchain_files!(platform; toolchains_path=toolchains_path)
generate_toolchain_files!(platform, envs; toolchains_path=toolchains_path)
push!(workspaces, toolchains_path => "/opt/toolchains")

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

2 comments on commit ccf3161

@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/49115

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 v1.0.3 -m "<description of version>" ccf316139d2c301e6f45f24cfe88e6961483c63e
git push origin v1.0.3

Please sign in to comment.