From owner-svn-ports-head@freebsd.org Fri Mar 12 09:53:27 2021 Return-Path: Delivered-To: svn-ports-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EE78C573D4B; Fri, 12 Mar 2021 09:53:27 +0000 (UTC) (envelope-from mikael@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Dxh2v6QBKz3Ksl; Fri, 12 Mar 2021 09:53:27 +0000 (UTC) (envelope-from mikael@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C45CA158BE; Fri, 12 Mar 2021 09:53:27 +0000 (UTC) (envelope-from mikael@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 12C9rRji006833; Fri, 12 Mar 2021 09:53:27 GMT (envelope-from mikael@FreeBSD.org) Received: (from mikael@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 12C9rRE5006832; Fri, 12 Mar 2021 09:53:27 GMT (envelope-from mikael@FreeBSD.org) Message-Id: <202103120953.12C9rRE5006832@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mikael set sender to mikael@FreeBSD.org using -f From: Mikael Urankar Date: Fri, 12 Mar 2021 09:53:27 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r568158 - head/devel/py-maturin/files X-SVN-Group: ports-head X-SVN-Commit-Author: mikael X-SVN-Commit-Paths: head/devel/py-maturin/files X-SVN-Commit-Revision: 568158 X-SVN-Commit-Repository: ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-head@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: SVN commit messages for the ports tree for head List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Mar 2021 09:53:28 -0000 Author: mikael Date: Fri Mar 12 09:53:27 2021 New Revision: 568158 URL: https://svnweb.freebsd.org/changeset/ports/568158 Log: devel/py-maturin: Fix build on aarch64 Approved by: portmgr (tier-2 blanket) Added: head/devel/py-maturin/files/patch-cargo-crates_ring-0.16.15_Cargo.toml (contents, props changed) head/devel/py-maturin/files/patch-cargo-crates_ring-0.16.15_src_cpu.rs (contents, props changed) Added: head/devel/py-maturin/files/patch-cargo-crates_ring-0.16.15_Cargo.toml ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/devel/py-maturin/files/patch-cargo-crates_ring-0.16.15_Cargo.toml Fri Mar 12 09:53:27 2021 (r568158) @@ -0,0 +1,11 @@ +--- cargo-crates/ring-0.16.15/Cargo.toml.orig 2021-03-12 09:29:47 UTC ++++ cargo-crates/ring-0.16.15/Cargo.toml +@@ -70,7 +70,7 @@ version = "1.3.1" + features = ["std"] + optional = true + default-features = false +-[target."cfg(any(target_os = \"android\", target_os = \"linux\"))".dependencies.libc] ++[target."cfg(any(target_os = \"android\", target_os = \"freebsd\", target_os = \"linux\"))".dependencies.libc] + version = "0.2.69" + default-features = false + [target."cfg(any(unix, windows))".dev-dependencies.libc] Added: head/devel/py-maturin/files/patch-cargo-crates_ring-0.16.15_src_cpu.rs ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/devel/py-maturin/files/patch-cargo-crates_ring-0.16.15_src_cpu.rs Fri Mar 12 09:53:27 2021 (r568158) @@ -0,0 +1,367 @@ +--- cargo-crates/ring-0.16.15/src/cpu.rs.orig 2021-03-12 09:24:30 UTC ++++ cargo-crates/ring-0.16.15/src/cpu.rs +@@ -24,16 +24,20 @@ pub(crate) struct Features(()); + + #[inline(always)] + pub(crate) fn features() -> Features { +- // We don't do runtime feature detection on iOS. instead some features are +- // assumed to be present; see `arm::Feature`. +- #[cfg(all( +- any( +- target_arch = "aarch64", +- target_arch = "arm", +- target_arch = "x86", +- target_arch = "x86_64" +- ), +- not(target_os = "ios") ++ // We don't do runtime feature detection on aarch64-apple-* as all AAarch64 ++ // features we use are available on every device since the first devices. ++ #[cfg(any( ++ target_arch = "x86", ++ target_arch = "x86_64", ++ all( ++ any(target_arch = "aarch64", target_arch = "arm"), ++ any( ++ target_os = "android", ++ target_os = "fuchsia", ++ target_os = "freebsd", ++ target_os = "linux" ++ ) ++ ) + ))] + { + static INIT: spin::Once<()> = spin::Once::new(); +@@ -49,17 +53,17 @@ pub(crate) fn features() -> Features { + } + + #[cfg(all( +- any(target_os = "android", target_os = "linux"), +- any(target_arch = "aarch64", target_arch = "arm") ++ any(target_arch = "aarch64", target_arch = "arm"), ++ any( ++ target_os = "android", ++ target_os = "fuchsia", ++ target_os = "freebsd", ++ target_os = "linux" ++ ) + ))] + { +- arm::linux_setup(); ++ arm::setup(); + } +- +- #[cfg(all(target_os = "fuchsia", any(target_arch = "aarch64")))] +- { +- arm::fuchsia_setup(); +- } + }); + } + +@@ -68,28 +72,57 @@ pub(crate) fn features() -> Features { + + pub(crate) mod arm { + #[cfg(all( +- any(target_os = "android", target_os = "linux"), ++ any(target_os = "android", target_os = "freebsd", target_os = "linux"), + any(target_arch = "aarch64", target_arch = "arm") + ))] +- pub fn linux_setup() { ++ pub fn setup() { + use libc::c_ulong; ++ #[cfg(target_os = "freebsd")] ++ use libc::{c_int, c_void}; ++ #[cfg(target_os = "freebsd")] ++ extern crate std; + + // XXX: The `libc` crate doesn't provide `libc::getauxval` consistently + // across all Android/Linux targets, e.g. musl. ++ #[cfg(any(target_os = "android", target_os = "linux"))] + extern "C" { + fn getauxval(type_: c_ulong) -> c_ulong; + } + ++ #[cfg(target_os = "freebsd")] ++ extern "C" { ++ fn elf_aux_info(aux: c_int, buf: *mut c_void, buflen: c_int) -> c_int; ++ } ++ ++ #[cfg(not(target_os = "freebsd"))] + const AT_HWCAP: c_ulong = 16; + ++ #[cfg(target_os = "freebsd")] ++ const AT_HWCAP: c_int = 25; ++ + #[cfg(target_arch = "aarch64")] + const HWCAP_NEON: c_ulong = 1 << 1; + + #[cfg(target_arch = "arm")] + const HWCAP_NEON: c_ulong = 1 << 12; + ++ #[cfg(not(target_os = "freebsd"))] + let caps = unsafe { getauxval(AT_HWCAP) }; + ++ #[cfg(target_os = "freebsd")] ++ let caps: c_ulong = 0; ++ ++ #[cfg(target_os = "freebsd")] ++ { ++ let buffer: *mut c_void = { ++ let t: *const c_ulong = ∩︀ ++ t ++ } as *mut c_void; ++ unsafe { ++ let _ret = elf_aux_info(AT_HWCAP, buffer, std::mem::size_of_val(&caps) as i32); ++ } ++ } ++ + // We assume NEON is available on AARCH64 because it is a required + // feature. + #[cfg(target_arch = "aarch64")] +@@ -106,12 +139,26 @@ pub(crate) mod arm { + #[cfg(target_arch = "arm")] + const OFFSET: c_ulong = 0; + +- #[cfg(target_arch = "arm")] ++ #[cfg(target_os = "freebsd")] ++ let buffer: *mut c_void = { ++ let t: *const c_ulong = ∩︀ ++ t ++ } as *mut c_void; ++ ++ #[cfg(not(target_os = "freebsd"))] + let caps = { + const AT_HWCAP2: c_ulong = 26; + unsafe { getauxval(AT_HWCAP2) } + }; + ++ #[cfg(target_os = "freebsd")] ++ { ++ const AT_HWCAP2: c_int = 26; ++ unsafe { ++ let _ret = elf_aux_info(AT_HWCAP2, buffer, std::mem::size_of_val(&caps) as i32); ++ }; ++ } ++ + const HWCAP_AES: c_ulong = 1 << 0 + OFFSET; + const HWCAP_PMULL: c_ulong = 1 << 1 + OFFSET; + const HWCAP_SHA2: c_ulong = 1 << 3 + OFFSET; +@@ -123,15 +170,15 @@ pub(crate) mod arm { + features |= PMULL.mask; + } + if caps & HWCAP_SHA2 == HWCAP_SHA2 { +- features |= 1 << 4; ++ features |= SHA256.mask; + } + + unsafe { GFp_armcap_P = features }; + } + } + +- #[cfg(all(target_os = "fuchsia", any(target_arch = "aarch64")))] +- pub fn fuchsia_setup() { ++ #[cfg(all(target_os = "fuchsia", target_arch = "aarch64"))] ++ pub fn setup() { + type zx_status_t = i32; + + #[link(name = "zircon")] +@@ -168,82 +215,139 @@ pub(crate) mod arm { + } + } + +- #[cfg(not(target_arch = "wasm32"))] ++ macro_rules! features { ++ { ++ $( ++ $name:ident { ++ mask: $mask:expr, ++ ++ /// Should we assume that the feature is always available ++ /// for aarch64-apple-* targets? The first AArch64 iOS ++ /// device used the Apple A7 chip. ++ // TODO: When we can use `if` in const expressions: ++ // ``` ++ // aarch64_apple: $aarch64_apple, ++ // ``` ++ aarch64_apple: true, ++ } ++ ),+ ++ , // trailing comma is required. ++ } => { ++ $( ++ #[allow(dead_code)] ++ pub(crate) const $name: Feature = Feature { ++ mask: $mask, ++ }; ++ )+ ++ ++ // TODO: When we can use `if` in const expressions, do this: ++ // ``` ++ // const ARMCAP_STATIC: u32 = 0 ++ // $( ++ // | ( if $aarch64_apple && ++ // cfg!(all(target_arch = "aarch64", ++ // target_vendor = "apple")) { ++ // $name.mask ++ // } else { ++ // 0 ++ // } ++ // ) ++ // )+; ++ // ``` ++ // ++ // TODO: Add static feature detection to other targets. ++ // TODO: Combine static feature detection with runtime feature ++ // detection. ++ #[cfg(all(target_arch = "aarch64", target_vendor = "apple"))] ++ const ARMCAP_STATIC: u32 = 0 ++ $( | $name.mask ++ )+; ++ #[cfg(not(all(target_arch = "aarch64", target_vendor = "apple")))] ++ const ARMCAP_STATIC: u32 = 0; ++ ++ #[cfg(all(target_arch = "aarch64", target_vendor = "apple"))] ++ #[test] ++ fn test_armcap_static_available() { ++ let features = crate::cpu::features(); ++ $( ++ assert!($name.available(features)); ++ )+ ++ } ++ } ++ } ++ ++ #[allow(dead_code)] + pub(crate) struct Feature { +- #[cfg_attr( +- any( +- target_os = "ios", +- not(any(target_arch = "arm", target_arch = "aarch64")) +- ), +- allow(dead_code) +- )] + mask: u32, +- +- #[cfg_attr(not(target_os = "ios"), allow(dead_code))] +- ios: bool, + } + +- #[cfg(not(target_arch = "wasm32"))] + impl Feature { ++ #[allow(dead_code)] + #[inline(always)] + pub fn available(&self, _: super::Features) -> bool { +- #[cfg(all(target_os = "ios", any(target_arch = "arm", target_arch = "aarch64")))] +- { +- return self.ios; ++ if self.mask == self.mask & ARMCAP_STATIC { ++ return true; + } + + #[cfg(all( +- any(target_os = "android", target_os = "linux", target_os = "fuchsia"), ++ any(target_os = "android", target_os = "fuchsia", target_os = "linux"), + any(target_arch = "arm", target_arch = "aarch64") + ))] + { +- return self.mask == self.mask & unsafe { GFp_armcap_P }; ++ if self.mask == self.mask & unsafe { GFp_armcap_P } { ++ return true; ++ } + } + +- #[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))] +- { +- return false; +- } ++ false + } + } + +- // Keep in sync with `ARMV7_NEON`. +- #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] +- pub(crate) const NEON: Feature = Feature { +- mask: 1 << 0, +- ios: true, +- }; ++ features! { ++ // Keep in sync with `ARMV7_NEON`. ++ NEON { ++ mask: 1 << 0, ++ aarch64_apple: true, ++ }, + +- // Keep in sync with `ARMV8_AES`. +- #[cfg(any( +- target_arch = "aarch64", +- target_arch = "arm", +- target_arch = "x86", +- target_arch = "x86_64" +- ))] +- pub(crate) const AES: Feature = Feature { +- mask: 1 << 2, +- ios: true, +- }; ++ // Keep in sync with `ARMV8_AES`. ++ AES { ++ mask: 1 << 2, ++ aarch64_apple: true, ++ }, + +- // Keep in sync with `ARMV8_PMULL`. +- #[cfg(any( +- target_arch = "aarch64", +- target_arch = "arm", +- target_arch = "x86", +- target_arch = "x86_64" +- ))] +- pub(crate) const PMULL: Feature = Feature { +- mask: 1 << 5, +- ios: true, +- }; ++ // Keep in sync with `ARMV8_SHA256`. ++ SHA256 { ++ mask: 1 << 4, ++ aarch64_apple: true, ++ }, + ++ // Keep in sync with `ARMV8_PMULL`. ++ PMULL { ++ mask: 1 << 5, ++ aarch64_apple: true, ++ }, ++ } ++ ++ // Some non-Rust code still checks this even when it is statically known ++ // the given feature is available, so we have to ensure that this is ++ // initialized properly. Keep this in sync with the initialization in ++ // BoringSSL's crypto.c. ++ // ++ // TODO: This should have "hidden" visibility but we don't have a way of ++ // controlling that yet: https://github.com/rust-lang/rust/issues/73958. ++ #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] ++ #[no_mangle] ++ static mut GFp_armcap_P: u32 = ARMCAP_STATIC; ++ + #[cfg(all( +- any(target_os = "android", target_os = "linux", target_os = "fuchsia"), +- any(target_arch = "arm", target_arch = "aarch64") ++ any(target_arch = "arm", target_arch = "aarch64"), ++ target_vendor = "apple" + ))] +- extern "C" { +- static mut GFp_armcap_P: u32; ++ #[test] ++ fn test_armcap_static_matches_armcap_dynamic() { ++ assert_eq!(ARMCAP_STATIC, 1 | 4 | 16 | 32); ++ assert_eq!(ARMCAP_STATIC, unsafe { GFp_armcap_P }); + } + } + +@@ -258,6 +362,7 @@ pub(crate) mod intel { + } + + impl Feature { ++ #[allow(clippy::needless_return)] + #[inline(always)] + pub fn available(&self, _: super::Features) -> bool { + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]