From nobody Sun Nov 24 08:56:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1725971803; cv=none; d=zohomail.com; s=zohoarc; b=FJYEp1xP+AgUELy8Bu6wVIQE8hum2/9t44Gvv4P3sTXw2krHPGzc6VhzuIiV1EsxyIlDfuFsbxUmcS9UgjLR4fHXuR20NBEL4sxkCvRWQ1qxgNmTHDhROuZ2+Dq3crrPi5znhGgdJTMJQ7u9udUDqZvETssv8QuiAvJ3ekA307E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725971803; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rTW6DB2vc7KmJQ4SGCbEmjnkV7PiKuK8fmowFe7ncik=; b=n4cywZ8tSmg6ZVSIZro65HHDweHkmzp99mJU+A1MvnSC+/ZykJcjqIz8Zzsn/o82U9lgwYtye7jbY4koWChAHxJSeL3VKCzBiCb5GJa9Zf8WMLsJnnDhpFhUb1wfJqpWd2OGHQyIjw1+w678gIu6n9oT8DacxdAWIV1TW1/HS2c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17259718031821003.0287103228305; Tue, 10 Sep 2024 05:36:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1so064-0008Oz-S8; Tue, 10 Sep 2024 08:35:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1so05u-0008Fn-0c for qemu-devel@nongnu.org; Tue, 10 Sep 2024 08:35:43 -0400 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so05r-0004pm-Oo for qemu-devel@nongnu.org; Tue, 10 Sep 2024 08:35:41 -0400 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5c26815e174so5886868a12.0 for ; Tue, 10 Sep 2024 05:35:39 -0700 (PDT) Received: from [127.0.1.1] (adsl-234.109.242.225.tellas.gr. [109.242.225.234]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd41cd7sm4242994a12.3.2024.09.10.05.35.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 05:35:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725971738; x=1726576538; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=rTW6DB2vc7KmJQ4SGCbEmjnkV7PiKuK8fmowFe7ncik=; b=yaCXLENpTtPeYyBcLiMRcTed8qQUX69X/sH1Wk5VAubCaxtNNurTJplBMauhvc543a XMepvrPm+IuBc8DvKrHSg9CkghhoBr0a6LwLdqOfeMS1Hx55JZyEizI1SJirec+5DZ66 y2J5pP6gkIQdNiGHzkND3Y3wG22QyUQIbyJ/inB+ldhobVoWMkNTax0zjpYyrN9rb4RH dDegKoIDfPhstuNmm6eUO14l8z4nQqJEqGhs8ktJ6QRySNpCGEO5DlIO93SoYgjOn4I2 Rt3mlModGEaade7eWYeeAzxYRaLOtfkSgwq5b4LP2jNNn0W9T99cSD/dI7CYpChGApmt w/9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725971738; x=1726576538; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rTW6DB2vc7KmJQ4SGCbEmjnkV7PiKuK8fmowFe7ncik=; b=UWNnr61QdhxUlLAFU5JLkHTnz4cPcDGxhesvX+a/jzSj2p4lHSRT/CO4ENiSkMR+ZD NV95kdD4aXsD55+z1Tz6qEGQDUv+PCQ8lCw5KZEKlG7do37JuGemuZDSADCptyyo3MbU lcNyeFWhW7N4rL/hlNp2TLWaOdI89IwqjhpCwnc3N7XDPCL9XRKOki3Jv+GnDcsxvUaY sHhn22/q9cdHgOgjakhDDldmXAdnvGvtsaajfEGhyTlSkFGWk1D6xFkkLwQodNuYiCSC Qq/MHlrJ9NGNXIqN/Di/zda+/HeHJxbyxLZ6S3rhvVjCU2TWZLGr7jnSqfpCGi0fXg2v TZLg== X-Gm-Message-State: AOJu0Yyzoibwnin6O2Iin9qxCpbf1dnZE2T3iA4drTbn6ylMaAd7bxaN IxBZZNen1J1QPTSNqV9/SKU75AWXH2ompL5ZGNMPxFcRWxYmHVymhG0k8BNdQlpOC1tNuFKanSc tiVM= X-Google-Smtp-Source: AGHT+IFNbMcnT433HCIsXxMp3sRrRiFp8P3Pm3LdplWrUdMZC6CsPSVMf+n/5T1/ZxDKtSzmMgd2Rw== X-Received: by 2002:a05:6402:350f:b0:5c0:c10c:7c1d with SMTP id 4fb4d7f45d1cf-5c3e9742e8fmr7604704a12.23.1725971738072; Tue, 10 Sep 2024 05:35:38 -0700 (PDT) From: Manos Pitsidianakis Date: Tue, 10 Sep 2024 15:35:09 +0300 Subject: [PATCH v10 3/9] configure, meson: detect Rust toolchain MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240910-rust-pl011-v10-3-85a89ee33c40@linaro.org> References: <20240910-rust-pl011-v10-0-85a89ee33c40@linaro.org> In-Reply-To: <20240910-rust-pl011-v10-0-85a89ee33c40@linaro.org> To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Richard Henderson , Gustavo Romero , =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell , Junjie Mao , Zhao Liu , John Snow , Cleber Rosa , Beraldo Leal , Wainer dos Santos Moschetta , qemu-arm@nongnu.org X-Mailer: b4 0.15-dev-c2c95 X-Developer-Signature: v=1; a=openpgp-sha256; l=10503; i=manos.pitsidianakis@linaro.org; h=from:subject:message-id; bh=hOhk5Oy02nnSK1uZVkNHltHu7gBfzMIt71sTA+argnc=; b=LS0tLS1CRUdJTiBQR1AgTUVTU0FHRS0tLS0tCgprQTBEQUFvQmR5bkhjSDkrQ2RBQnl5WmlBR 2JnUFF1Z0lwenhrdGdVRkxhVSsxNXFkV09qS2Mwcmh4eUJPY2hMCmFvcnYwWWc0eVlrQ013UUFB UW9BSFJZaEJNeGNHMDVFb0ZiemgzQWRFSGNweDNCL2ZnblFCUUptNEQwTEFBb0oKRUhjcHgzQi9 mZ25RMjZnUC8wdkxqc0lOSEZ0WXlTbE1CVUozaHlnck55d1V6YytuNm9XbG9Talp6YzRpTVllbw o3eDdNdVJzbTN0aXh0Z1hwcE9sQk5oSXFyazdYTDB4UkNIQUNrem5WNmJsK1lLL0RXc2tWK1N5T mM5MXBLcmJkCnlxaktpcW9sZmZMeTRWSWN2dGpkUkx4clIvNlI1RDAyZUlSUDcyQUhlamFVMmdW SHlCeldmMXdhKzFZVGMyQnUKVzhFaU5ra3Qza0swUjdSeTBKSkpnMXJpWTJ6U2Z4aXpPbWNCSHd 1VUtDTEUxVmJ0OSt1WHlYbWdCUDNHVDVYVwpHaHNqV2l5MmgrckdORGI4WGxlYU5KTUc5QlpYOU FLbWZtU2RIWkFyOFJuOTBzZEpjWFNYR1dqV0EyNGtCTDZWCjR6S2gvdFQwZWpqaGZ0K012MHk5Z TNoaHlwTzVTbGlOTzI2cnhyQmlnSVM1cEpUbXJOY1NXZS9mNmpseGRBR3EKOTBKVmN5MDRSNHBy T3p0VTREVkVNLzdJcHhlWjBvYm00U1ZITFkySHh5dElDY0JVSFo5eXlvaUhmZXl0YVVjaQpoZWJ wL3doWlpvWTgrN00zMDJnenZRVzFqYzRBd0Exa0hiZnpXSFBqMGR0TnFCTytvOERkWGVSeGgvbF Q0QllnCmNZVGFWMzVIWUIzVFRzdVBoQ25KY0dHMTVTTlJ3encwK2pKeDZZUlRIRFhRVEt3VVpaZ nRKZEhmRW5kOFU3ZzgKdkNXSThrM09iblZNdGl2djZFTW1vV3h1cjhlbExFM2NHVkpGRVJPZkJv NjdjRDB2bG5KNkV0NnlHdDZnMnVZWApqMlk5ZmMyTjZjY3Y0T05ySG5LZ2pOS1k1V3VYMFhZSnN zU2pOY1ZhbmE3c0l1NWk4c0Z3ZzBqTmpPYTcKPXpreUsKLS0tLS1FTkQgUEdQIE1FU1NBR0UtLS 0tLQo= X-Developer-Key: i=manos.pitsidianakis@linaro.org; a=openpgp; fpr=7C721DF9DB3CC7182311C0BF68BC211D47B421E1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52d; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-ed1-x52d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1725971804242116600 From: Paolo Bonzini Include the correct path and arguments to rustc in the native and cross files (native compilation is needed for procedural macros). Based on the host architecture and OS, the compiler and optionally the argu= ment to --cpu, the Rust target triple can be detected automatically for either a native or a cross compiler. In general, it is only a matter of translating the architecture and OS, and adding a machine to form the triple, but there are some special cases (e.g. detecting soft vs. hard floating point on ARM) and some inconsistencies. Signed-off-by: Paolo Bonzini --- configure | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++- meson.build | 5 +- 2 files changed, 164 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 019fcbd0ef7b07e7b0280b358099cae72c73aa98..4a011ff60bb8f351b3ee8d038a3= 5a249dc297831 100755 --- a/configure +++ b/configure @@ -207,6 +207,8 @@ for opt do ;; --objcc=3D*) objcc=3D"$optarg" ;; + --rustc=3D*) RUSTC=3D"$optarg" + ;; --cpu=3D*) cpu=3D"$optarg" ;; --extra-cflags=3D*) @@ -252,6 +254,8 @@ python=3D download=3D"enabled" skip_meson=3Dno use_containers=3D"yes" +rust=3D"auto" +rust_target_triple=3D"" gdb_bin=3D$(command -v "gdb-multiarch" || command -v "gdb") gdb_arches=3D"" =20 @@ -310,6 +314,7 @@ objcopy=3D"${OBJCOPY-${cross_prefix}objcopy}" ld=3D"${LD-${cross_prefix}ld}" ranlib=3D"${RANLIB-${cross_prefix}ranlib}" nm=3D"${NM-${cross_prefix}nm}" +readelf=3D"${READELF-${cross_prefix}readelf}" strip=3D"${STRIP-${cross_prefix}strip}" widl=3D"${WIDL-${cross_prefix}widl}" windres=3D"${WINDRES-${cross_prefix}windres}" @@ -317,6 +322,8 @@ windmc=3D"${WINDMC-${cross_prefix}windmc}" pkg_config=3D"${PKG_CONFIG-${cross_prefix}pkg-config}" sdl2_config=3D"${SDL2_CONFIG-${cross_prefix}sdl2-config}" =20 +rustc=3D"${RUSTC-rustc}" + check_define() { cat > $TMPC < "${TMPDIR1}/= ${TMPB}.out"; then + rust_host_triple=3D$(sed -n 's/^host: //p' "${TMPDIR1}/${TMPB}.out") +else + if test "$rust" =3D enabled; then + error_exit "could not execute rustc binary \"$rustc\"" + fi + rust=3Ddisabled +fi +if test "$rust" !=3D disabled && test -z "$rust_target_triple"; then + # arch and os generally matches between meson and rust + rust_arch=3D$host_arch + rust_os=3D$host_os + rust_machine=3Dunknown + rust_osvariant=3D + + # tweak rust_os if needed; also, machine and variant depend on the OS + android=3Dno + case "$host_os" in + darwin) + # e.g. aarch64-apple-darwin + rust_machine=3Dapple + ;; + + linux) + # detect android/glibc/musl + if check_define __ANDROID__; then + rust_osvariant=3Dandroid + android=3Dyes + else + cat > $TMPC << EOF +#define _GNU_SOURCE +#include +#ifndef __USE_GNU +error using musl +#endif +EOF + if compile_object; then + rust_osvariant=3Dgnu + else + rust_osvariant=3Dmusl + fi + fi + + case "$host_arch" in + arm) + # e.g. arm-unknown-linux-gnueabi, arm-unknown-linux-gnueabihf + write_c_skeleton + compile_object + if $READELF -A $TMPO | grep Tag_API_VFP_args: > /dev/null; then + rust_osvariant=3D${rust_osvariant}eabihf + else + rust_osvariant=3D${rust_osvariant}eabi + fi + ;; + + mips64) + # e.g. mips64-unknown-linux-gnuabi64 + rust_osvariant=3D${rust_osvariant}abi64 + ;; + esac + ;; + + netbsd) + # e.g. arm-unknown-netbsd-eabihf + test "$host_arch" =3D arm && rust_osvariant=3Deabihf + ;; + + sunos) + rust_machine=3Dpc + rust_os=3Dsolaris + ;; + + windows) + # e.g. aarch64-pc-windows-gnullvm, x86_64-pc-windows-gnu (MSVC not sup= ported) + rust_machine=3Dpc + if test "$host_arch" =3D aarch64; then + rust_osvariant=3Dgnullvm + else + rust_osvariant=3Dgnu + fi + ;; + esac + + # now tweak the architecture part, possibly based on pre-canonicalizatio= n --cpu + case "$host_arch" in + arm) + # preserve ISA version (armv7 etc.) from $raw_cpu if passed via --cpu + rust_arch=3D$raw_cpu + test "$rust_arch" =3D arm && test "$rust_os" !=3D linux && rust_arch= =3Darmv7 + ;; + + mips|mips64) + # preserve ISA version (mipsisa64r6 etc.) and include endianness + rust_arch=3D${raw_cpu%el} + test "$bigendian" =3D no && rust_arch=3D${rust_arch}el + ;; + + riscv32|riscv64) + # e.g. riscv64gc-unknown-linux-gnu, but riscv64-linux-android + test "$android" =3D no && rust_arch=3D${rust_arch}gc + ;; + + sparc64) + if test "$rust_os" =3D solaris; then + rust_arch=3Dsparcv9 + rust_machine=3Dsun + fi + ;; + + x86_64) + # e.g. x86_64-unknown-linux-gnux32 + test "$raw_cpu" =3D x32 && rust_osvariant=3D${rust_osvariant}x32 + ;; + esac + + if test "$android" =3D yes; then + # e.g. aarch64-linux-android + rust_target_triple=3D$rust_arch-$rust_os-$rust_osvariant + else + rust_target_triple=3D$rust_arch-$rust_machine-$rust_os${rust_osvariant= +-$rust_osvariant} + fi +fi + +########################################## # functions to probe cross compilers =20 container=3D"no" @@ -1604,6 +1748,9 @@ if test "$container" !=3D no; then echo "RUNC=3D$runc" >> $config_host_mak fi echo "SUBDIRS=3D$subdirs" >> $config_host_mak +if test "$rust" !=3D disabled; then + echo "RUST_TARGET_TRIPLE=3D$rust_target_triple" >> $config_host_mak +fi echo "PYTHON=3D$python" >> $config_host_mak echo "MKVENV_ENSUREGROUP=3D$mkvenv ensuregroup $mkvenv_online_flag" >> $co= nfig_host_mak echo "GENISOIMAGE=3D$genisoimage" >> $config_host_mak @@ -1735,12 +1882,20 @@ if test "$skip_meson" =3D no; then echo "c =3D [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross test -n "$cxx" && echo "cpp =3D [$(meson_quote $cxx $CPU_CFLAGS)]" >> $c= ross test -n "$objcc" && echo "objc =3D [$(meson_quote $objcc $CPU_CFLAGS)]" = >> $cross + if test "$rust" !=3D disabled; then + if test "$rust_host_triple" !=3D "$rust_target_triple"; then + echo "rust =3D [$(meson_quote $rustc --target "$rust_target_triple")= ]" >> $cross + else + echo "rust =3D [$(meson_quote $rustc)]" >> $cross + fi + fi echo "ar =3D [$(meson_quote $ar)]" >> $cross echo "dlltool =3D [$(meson_quote $dlltool)]" >> $cross echo "nm =3D [$(meson_quote $nm)]" >> $cross echo "pkgconfig =3D [$(meson_quote $pkg_config)]" >> $cross echo "pkg-config =3D [$(meson_quote $pkg_config)]" >> $cross echo "ranlib =3D [$(meson_quote $ranlib)]" >> $cross + echo "readelf =3D [$(meson_quote $readelf)]" >> $cross if has $sdl2_config; then echo "sdl2-config =3D [$(meson_quote $sdl2_config)]" >> $cross fi @@ -1770,6 +1925,9 @@ if test "$skip_meson" =3D no; then echo "# Automatically generated by configure - do not modify" > $native echo "[binaries]" >> $native echo "c =3D [$(meson_quote $host_cc)]" >> $native + if test "$rust" !=3D disabled; then + echo "rust =3D [$(meson_quote $rustc)]" >> $cross + fi mv $native config-meson.native meson_option_add --native-file meson_option_add config-meson.native @@ -1788,6 +1946,7 @@ if test "$skip_meson" =3D no; then test "$pie" =3D no && meson_option_add -Db_pie=3Dfalse =20 # QEMU options + test "$rust" !=3D "auto" && meson_option_add "-Drust=3D$rust" test "$cfi" !=3D false && meson_option_add "-Dcfi=3D$cfi" "-Db_lto=3D$cf= i" test "$docs" !=3D auto && meson_option_add "-Ddocs=3D$docs" test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engin= e=3D$LIB_FUZZING_ENGINE" diff --git a/meson.build b/meson.build index 47a9c04e322a2171daf188eb62b7b4ad941c9ea8..065739ccb7300f4f0d487602485= 802f9f68fb095 100644 --- a/meson.build +++ b/meson.build @@ -4304,8 +4304,9 @@ else endif summary_info +=3D {'Rust support': have_rust} if have_rust - summary_info +=3D {'rustc version': rustc.version()} - summary_info +=3D {'rustc': ' '.join(rustc.cmd_array())} + summary_info +=3D {'rustc version': rustc.version()} + summary_info +=3D {'rustc': ' '.join(rustc.cmd_array())} + summary_info +=3D {'Rust target': config_host['RUST_TARGET_TRIPLE']} endif option_cflags =3D (get_option('debug') ? ['-g'] : []) if get_option('optimization') !=3D 'plain' --=20 2.45.2