Skip to content

Commit cb586ae

Browse files
committed
Fix build for various targets
1 parent 0d8dbaf commit cb586ae

File tree

5 files changed

+114
-35
lines changed

5 files changed

+114
-35
lines changed

.github/workflows/rust.yml

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ jobs:
3232
with:
3333
python-version: "3.14"
3434
- name: Setup Rust
35-
uses: actions-rs/toolchain@v1
36-
with:
37-
profile: minimal
38-
toolchain: ${{ matrix.rust }}
39-
override: true
35+
uses: dtolnay/rust-toolchain@stable
4036
- name: Build
4137
run: cargo build --verbose
4238
- name: Run tests with num-bigint
@@ -45,3 +41,72 @@ jobs:
4541
run: cargo test --verbose --features ${{ matrix.features }},num-bigint --release
4642
- name: Run tests with malachite-bigint
4743
run: cargo test --verbose --features ${{ matrix.features }},malachite-bigint
44+
45+
# macOS-specific cross-compilation checks
46+
- name: Setup Intel macOS target
47+
if: runner.os == 'macOS'
48+
run: rustup target add x86_64-apple-darwin
49+
- name: Check Intel macOS
50+
if: runner.os == 'macOS'
51+
run: cargo check --target x86_64-apple-darwin --features ${{ matrix.features }},malachite-bigint
52+
53+
- name: Setup iOS target
54+
if: runner.os == 'macOS'
55+
run: rustup target add aarch64-apple-ios
56+
- name: Check iOS
57+
if: runner.os == 'macOS'
58+
run: cargo check --target aarch64-apple-ios --features ${{ matrix.features }},malachite-bigint
59+
60+
exotic_targets:
61+
name: Check exotic targets
62+
runs-on: ubuntu-latest
63+
steps:
64+
- uses: actions/checkout@v4
65+
- uses: dtolnay/rust-toolchain@stable
66+
67+
# 32-bit Linux
68+
- name: Setup i686-unknown-linux-gnu
69+
run: rustup target add i686-unknown-linux-gnu
70+
- name: Install gcc-multilib
71+
run: sudo apt-get update && sudo apt-get install -y gcc-multilib
72+
- name: Check i686-unknown-linux-gnu
73+
run: cargo check --target i686-unknown-linux-gnu --features complex,malachite-bigint
74+
75+
# Android
76+
- name: Setup aarch64-linux-android
77+
run: rustup target add aarch64-linux-android
78+
- name: Check aarch64-linux-android
79+
run: cargo check --target aarch64-linux-android --features complex,malachite-bigint
80+
81+
# ARM64 Linux
82+
- name: Setup aarch64-unknown-linux-gnu
83+
run: rustup target add aarch64-unknown-linux-gnu
84+
- name: Install gcc-aarch64-linux-gnu
85+
run: sudo apt-get install -y gcc-aarch64-linux-gnu
86+
- name: Check aarch64-unknown-linux-gnu
87+
run: cargo check --target aarch64-unknown-linux-gnu --features complex,malachite-bigint
88+
89+
# musl
90+
- name: Setup i686-unknown-linux-musl
91+
run: rustup target add i686-unknown-linux-musl
92+
- name: Install musl-tools
93+
run: sudo apt-get install -y musl-tools
94+
- name: Check i686-unknown-linux-musl
95+
run: cargo check --target i686-unknown-linux-musl --features complex,malachite-bigint
96+
97+
# FreeBSD
98+
- name: Setup x86_64-unknown-freebsd
99+
run: rustup target add x86_64-unknown-freebsd
100+
- name: Check x86_64-unknown-freebsd
101+
run: cargo check --target x86_64-unknown-freebsd --features complex,malachite-bigint
102+
103+
clippy:
104+
name: Clippy
105+
runs-on: ubuntu-latest
106+
steps:
107+
- uses: actions/checkout@v4
108+
- uses: dtolnay/rust-toolchain@stable
109+
with:
110+
components: clippy
111+
- name: Run clippy
112+
run: cargo clippy --features complex,malachite-bigint -- -Dwarnings

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
22
name = "pymath"
3-
author = "Jeong, YunWon <[email protected]>"
3+
authors = ["Jeong, YunWon <[email protected]>"]
44
repository = "https://github.com/RustPython/pymath"
55
description = "A binary representation compatible Rust implementation of Python's math library."
6-
version = "0.1.2"
6+
version = "0.1.3"
77
edition = "2024"
88
license = "PSF-2.0"
99

src/err.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ pub(crate) fn set_errno(value: i32) {
2929
{
3030
*libc::__errno_location() = value;
3131
}
32+
#[cfg(target_os = "android")]
33+
{
34+
*libc::__errno() = value;
35+
}
3236
#[cfg(target_os = "macos")]
3337
{
3438
*libc::__error() = value;
@@ -40,7 +44,10 @@ pub(crate) fn set_errno(value: i32) {
4044
}
4145
*_errno() = value;
4246
}
43-
#[cfg(all(unix, not(any(target_os = "linux", target_os = "macos"))))]
47+
#[cfg(all(
48+
unix,
49+
not(any(target_os = "linux", target_os = "android", target_os = "macos"))
50+
))]
4451
{
4552
// FreeBSD, NetBSD, OpenBSD, etc. use __error()
4653
*libc::__error() = value;
@@ -56,6 +63,10 @@ pub(crate) fn get_errno() -> i32 {
5663
{
5764
*libc::__errno_location()
5865
}
66+
#[cfg(target_os = "android")]
67+
{
68+
*libc::__errno()
69+
}
5970
#[cfg(target_os = "macos")]
6071
{
6172
*libc::__error()
@@ -67,7 +78,10 @@ pub(crate) fn get_errno() -> i32 {
6778
}
6879
*_errno()
6980
}
70-
#[cfg(all(unix, not(any(target_os = "linux", target_os = "macos"))))]
81+
#[cfg(all(
82+
unix,
83+
not(any(target_os = "linux", target_os = "android", target_os = "macos"))
84+
))]
7185
{
7286
// FreeBSD, NetBSD, OpenBSD, etc. use __error()
7387
*libc::__error()

src/math/bigint.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ pub fn log_bigint(n: &BigInt, base: Option<f64>) -> crate::Result<f64> {
110110
}
111111

112112
// Try direct conversion first
113-
if let Some(x) = n.to_f64() {
114-
if x.is_finite() {
115-
return super::log(x, base);
116-
}
113+
if let Some(x) = n.to_f64()
114+
&& x.is_finite()
115+
{
116+
return super::log(x, base);
117117
}
118118

119119
// Use frexp decomposition for large values
@@ -141,10 +141,10 @@ pub fn log2_bigint(n: &BigInt) -> crate::Result<f64> {
141141
}
142142

143143
// Try direct conversion first
144-
if let Some(x) = n.to_f64() {
145-
if x.is_finite() {
146-
return super::log2(x);
147-
}
144+
if let Some(x) = n.to_f64()
145+
&& x.is_finite()
146+
{
147+
return super::log2(x);
148148
}
149149

150150
// Use frexp decomposition for large values
@@ -162,10 +162,10 @@ pub fn log10_bigint(n: &BigInt) -> crate::Result<f64> {
162162
}
163163

164164
// Try direct conversion first
165-
if let Some(x) = n.to_f64() {
166-
if x.is_finite() {
167-
return super::log10(x);
168-
}
165+
if let Some(x) = n.to_f64()
166+
&& x.is_finite()
167+
{
168+
return super::log10(x);
169169
}
170170

171171
// Use frexp decomposition for large values

src/math/integer.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ fn approximate_isqrt(n: u64) -> u32 {
8080

8181
/// Return the integer part of the square root of a non-negative integer.
8282
///
83-
/// Returns Err if n is negative.
84-
pub fn isqrt(n: &BigInt) -> Result<BigInt, ()> {
83+
/// Returns Err(EDOM) if n is negative.
84+
pub fn isqrt(n: &BigInt) -> crate::Result<BigInt> {
8585
if n.is_negative() {
86-
return Err(());
86+
return Err(crate::Error::EDOM);
8787
}
88-
Ok(isqrt_unsigned(&n.magnitude()).into())
88+
Ok(isqrt_unsigned(n.magnitude()).into())
8989
}
9090

9191
/// Return the integer part of the square root of the input.
@@ -233,12 +233,12 @@ fn factorial_odd_part(n: u64) -> BigUint {
233233

234234
/// Return n factorial (n!).
235235
///
236-
/// Returns Err(()) if n is negative.
236+
/// Returns Err(EDOM) if n is negative.
237237
/// Uses the divide-and-conquer algorithm.
238238
/// Based on: http://www.luschny.de/math/factorial/binarysplitfact.html
239-
pub fn factorial(n: i64) -> Result<BigUint, ()> {
239+
pub fn factorial(n: i64) -> crate::Result<BigUint> {
240240
if n < 0 {
241-
return Err(());
241+
return Err(crate::Error::EDOM);
242242
}
243243
let n = n as u64;
244244
// Use lookup table for small values
@@ -652,12 +652,12 @@ pub(super) fn perm_comb_small(n: u64, k: u64, is_comb: bool) -> BigUint {
652652

653653
/// Return the number of ways to choose k items from n items (n choose k).
654654
///
655-
/// Returns Err(()) if n or k is negative.
655+
/// Returns Err(EDOM) if n or k is negative.
656656
/// Evaluates to n! / (k! * (n - k)!) when k <= n and evaluates
657657
/// to zero when k > n.
658-
pub fn comb(n: i64, k: i64) -> Result<BigUint, ()> {
658+
pub fn comb(n: i64, k: i64) -> crate::Result<BigUint> {
659659
if n < 0 || k < 0 {
660-
return Err(());
660+
return Err(crate::Error::EDOM);
661661
}
662662
let (n, k) = (n as u64, k as u64);
663663
if k > n {
@@ -679,19 +679,19 @@ pub fn comb(n: i64, k: i64) -> Result<BigUint, ()> {
679679

680680
/// Return the number of ways to arrange k items from n items.
681681
///
682-
/// Returns Err(()) if n or k is negative.
682+
/// Returns Err(EDOM) if n or k is negative.
683683
/// Evaluates to n! / (n - k)! when k <= n and evaluates
684684
/// to zero when k > n.
685685
///
686686
/// If k is not specified (None), then k defaults to n
687687
/// and the function returns n!.
688-
pub fn perm(n: i64, k: Option<i64>) -> Result<BigUint, ()> {
688+
pub fn perm(n: i64, k: Option<i64>) -> crate::Result<BigUint> {
689689
if n < 0 {
690-
return Err(());
690+
return Err(crate::Error::EDOM);
691691
}
692692
let n = n as u64;
693693
let k = match k {
694-
Some(k) if k < 0 => return Err(()),
694+
Some(k) if k < 0 => return Err(crate::Error::EDOM),
695695
Some(k) => k as u64,
696696
None => n,
697697
};

0 commit comments

Comments
 (0)