core/pkgs/build-support/lib/meson.nix

42 lines
1.2 KiB
Nix
Raw Normal View History

2024-05-02 00:46:19 +00:00
{ stdenv, lib }:
let
inherit (lib) boolToString optionals;
# See https://mesonbuild.com/Reference-tables.html#cpu-families
2024-05-13 21:24:10 +00:00
cpuFamily = platform:
with platform;
if isAarch32 then
"arm"
else if isx86_32 then
"x86"
else
platform.uname.processor;
2024-05-02 00:46:19 +00:00
crossFile = builtins.toFile "cross-file.conf" ''
[properties]
bindgen_clang_arguments = ['-target', '${stdenv.targetPlatform.config}']
2024-05-13 21:24:10 +00:00
needs_exe_wrapper = ${
boolToString (!stdenv.buildPlatform.canExecute stdenv.hostPlatform)
}
2024-05-02 00:46:19 +00:00
[host_machine]
system = '${stdenv.targetPlatform.parsed.kernel.name}'
cpu_family = '${cpuFamily stdenv.targetPlatform}'
cpu = '${stdenv.targetPlatform.parsed.cpu.name}'
2024-05-13 21:24:10 +00:00
endian = ${
if stdenv.targetPlatform.isLittleEndian then "'little'" else "'big'"
}
2024-05-02 00:46:19 +00:00
[binaries]
llvm-config = 'llvm-config-native'
rust = ['rustc', '--target', '${stdenv.targetPlatform.rust.rustcTargetSpec}']
'';
2024-05-13 21:24:10 +00:00
crossFlags = optionals (stdenv.hostPlatform != stdenv.buildPlatform)
[ "--cross-file=${crossFile}" ];
2024-05-02 00:46:19 +00:00
2024-05-13 21:24:10 +00:00
makeMesonFlags = { mesonFlags ? [ ], ... }: crossFlags ++ mesonFlags;
2024-05-02 00:46:19 +00:00
2024-05-13 21:24:10 +00:00
in { inherit makeMesonFlags; }