Skip to content

Commit 792db09

Browse files
authored
Merge pull request #88 from madsmtm/better-32bit-support
Test 32-bit support in CI
2 parents fcecbf0 + 73012aa commit 792db09

File tree

6 files changed

+119
-24
lines changed

6 files changed

+119
-24
lines changed

.github/workflows/apple.yml

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ env:
1010
RUST_BACKTRACE: 1
1111
# Faster compilation and error on warnings
1212
RUSTFLAGS: "-C debuginfo=0 -D warnings"
13+
RUSTDOCFLAGS: "-D warnings"
14+
CARGO_TERM_VERBOSE: true
1315

1416
jobs:
1517
fmt:
@@ -61,19 +63,50 @@ jobs:
6163
- name: Check documentation
6264
uses: actions-rs/cargo@v1
6365
with:
64-
# TODO: Disallow warnings here
6566
command: doc
66-
args: --verbose --no-deps --document-private-items
67+
args: --no-deps --document-private-items
6768

6869
- name: Test without features
6970
uses: actions-rs/cargo@v1
7071
with:
7172
command: test
72-
args: --verbose --no-fail-fast --no-default-features
73+
args: --no-fail-fast --no-default-features
7374

7475
- name: Test with features
7576
uses: actions-rs/cargo@v1
7677
with:
7778
command: test
7879
# Not using --all-features because some features are nightly-only
79-
args: --verbose --no-fail-fast --features block,exception,catch_all,verify_message
80+
args: --no-fail-fast --features block,exception,catch_all,verify_message
81+
82+
build_32_bit:
83+
name: Build 32-bit
84+
85+
# 32-bit support was removed in 10.15, so we can't test the binary, only build it
86+
runs-on: macos-10.15
87+
88+
env:
89+
CARGO_BUILD_TARGET: i686-apple-darwin
90+
91+
steps:
92+
- uses: actions/checkout@v2
93+
94+
- name: Install nightly Rust # required for -Zbuild-std
95+
uses: actions-rs/toolchain@v1
96+
with:
97+
toolchain: nightly
98+
profile: minimal
99+
override: true
100+
components: rust-src
101+
102+
- name: Download macOS 10.13 SDK (supports 32-bit)
103+
run: |
104+
wget https://github.com/alexey-lysiuk/macos-sdk/releases/download/10.13/MacOSX10.13.tar.bz2
105+
tar -xyf MacOSX10.13.tar.bz2
106+
echo "SDKROOT=$(pwd)/MacOSX10.13.sdk" >> $GITHUB_ENV
107+
108+
- name: Build with features
109+
uses: actions-rs/cargo@v1
110+
with:
111+
command: build
112+
args: -Zbuild-std --tests --features exception,catch_all,verify_message

.github/workflows/gnustep.yml

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,47 @@ env:
1010
RUST_BACKTRACE: 1
1111
# Faster compilation and error on warnings
1212
RUSTFLAGS: "-C debuginfo=0 -D warnings"
13+
RUSTDOCFLAGS: "-D warnings"
14+
CARGO_TERM_VERBOSE: true
1315
CC: clang
1416
CXX: clang++
1517

1618
jobs:
1719
test:
1820
name: Test
19-
# TODO: 32bit and gcc-multilib
21+
strategy:
22+
matrix:
23+
platform:
24+
- target: x86_64-unknown-linux-gnu
25+
26+
- target: i686-unknown-linux-gnu
27+
cflags: -m32
28+
configureflags: --target=x86-pc-linux-gnu
29+
2030
runs-on: ubuntu-latest
2131

32+
env:
33+
CARGO_BUILD_TARGET: ${{ matrix.platform.target }}
34+
CFLAGS: ${{ matrix.platform.cflags }}
35+
CXXFLAGS: ${{ matrix.platform.cflags }}
36+
ASMFLAGS: ${{ matrix.platform.cflags }}
37+
LDFLAGS: ${{ matrix.platform.cflags }}
38+
2239
steps:
2340
- uses: actions/checkout@v2
2441

2542
- name: Install Clang
2643
run: sudo apt-get -y install clang
2744

45+
- name: Install cross compilation tools
46+
if: contains(matrix.platform.target, 'i686')
47+
run: |
48+
sudo dpkg --add-architecture i386
49+
sudo apt-get update
50+
sudo apt-get -y install gcc-multilib libgcc-10-dev:i386 \
51+
libc6-dev:i386 libstdc++-10-dev:i386 libffi-dev:i386 \
52+
libxml2-dev:i386 libicu-dev:i386
53+
2854
- name: Cache GNUStep
2955
id: cache-gnustep
3056
uses: actions/cache@v2
@@ -42,7 +68,7 @@ jobs:
4268
path: |
4369
~/gnustep/lib
4470
~/gnustep/include
45-
key: gnustep-libobjc2_1.9-make_2.9.0-base_1.28.0
71+
key: ${{ matrix.platform.target }}-gnustep-libobjc2_1.9-make_2.9.0-base_1.28.0
4672

4773
- name: Setup environment
4874
run: |
@@ -83,7 +109,7 @@ jobs:
83109
wget https://github.com/gnustep/libs-base/archive/refs/tags/base-1_28_0.tar.gz
84110
tar -xzf base-1_28_0.tar.gz
85111
cd libs-base-base-1_28_0
86-
./configure --prefix=$HOME/gnustep --disable-tls --disable-xslt
112+
./configure --prefix=$HOME/gnustep --disable-tls --disable-xslt ${{ matrix.platform.configureflags }}
87113
make install
88114
ls -al $HOME/gnustep/*
89115
@@ -93,25 +119,33 @@ jobs:
93119
path: |
94120
~/.cargo/
95121
target/
96-
key: gnustep-cargo-${{ hashFiles('**/Cargo.toml') }}
122+
key: ${{ matrix.platform.target }}-gnustep-cargo-${{ hashFiles('**/Cargo.toml') }}
97123
restore-keys: |
98-
gnustep-cargo-
124+
${{ matrix.platform.target }}-gnustep-cargo-
125+
126+
- name: Install Rust toolchain
127+
uses: actions-rs/toolchain@v1
128+
with:
129+
toolchain: stable
130+
target: ${{ matrix.platform.target }}
131+
profile: minimal
132+
override: true
99133

100134
- name: Run checks
101135
uses: actions-rs/cargo@v1
102136
with:
103137
command: check
104-
args: --verbose --no-default-features --features gnustep-1-9
138+
args: --no-default-features --features gnustep-1-9
105139

106140
- name: Test without features
107141
uses: actions-rs/cargo@v1
108142
with:
109143
command: test
110-
args: --verbose --no-fail-fast --no-default-features --features gnustep-1-9
144+
args: --no-fail-fast --no-default-features --features gnustep-1-9
111145

112146
- name: Test with features
113147
uses: actions-rs/cargo@v1
114148
with:
115149
command: test
116150
# Not using --all-features because some features are nightly-only
117-
args: --verbose --no-fail-fast --features gnustep-1-9,block,exception,catch_all,verify_message
151+
args: --no-fail-fast --features gnustep-1-9,block,exception,catch_all,verify_message

objc-sys/build.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,16 @@ fn main() {
164164

165165
let clang_runtime = match &runtime {
166166
Apple(runtime) => {
167-
let clang_runtime_str = match runtime {
168-
MacOS(_) => "macosx",
169-
IOS(_) => "ios",
170-
WatchOS(_) => "watchos",
171-
TvOS(_) => "ios", // ??
167+
// The fragile runtime is expected on i686-apple-darwin, see:
168+
// https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/Driver/ToolChains/Darwin.h#L228-L231
169+
// https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/Driver/ToolChains/Clang.cpp#L3639-L3640
170+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
171+
let clang_runtime_str = match (runtime, &*target_arch) {
172+
(MacOS(_), "x86") => "macosx-fragile",
173+
(MacOS(_), _) => "macosx",
174+
(IOS(_), _) => "ios",
175+
(WatchOS(_), _) => "watchos",
176+
(TvOS(_), _) => "ios", // ??
172177
};
173178
match runtime {
174179
MacOS(version) | IOS(version) | WatchOS(version) | TvOS(version) => {

objc-sys/src/various.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use core::ffi::c_void;
33
use std::os::raw::c_uint;
44
use std::os::raw::{c_char, c_int};
55

6-
#[cfg(apple)]
7-
use crate::objc_class;
86
use crate::{objc_AssociationPolicy, objc_object, OpaqueData, BOOL};
97

108
/// An opaque type that represents an instance variable.
@@ -24,13 +22,14 @@ pub type IMP = Option<unsafe extern "C" fn()>;
2422
/// Remember that this is non-null!
2523
#[cfg(all(apple, not(all(target_os = "macos", target_arch = "x86"))))]
2624
pub type objc_hook_getClass =
27-
unsafe extern "C" fn(name: *const c_char, out_cls: *mut *const objc_class) -> BOOL;
25+
unsafe extern "C" fn(name: *const c_char, out_cls: *mut *const crate::objc_class) -> BOOL;
2826

2927
/// Not available on macOS x86.
3028
///
3129
/// Remember that this is non-null!
3230
#[cfg(all(apple, not(all(target_os = "macos", target_arch = "x86"))))]
33-
pub type objc_hook_lazyClassNamer = unsafe extern "C" fn(cls: *const objc_class) -> *const c_char;
31+
pub type objc_hook_lazyClassNamer =
32+
unsafe extern "C" fn(cls: *const crate::objc_class) -> *const c_char;
3433

3534
extern "C" {
3635
pub fn imp_getBlock(imp: IMP) -> *mut objc_object;

objc2-foundation/src/enumerator.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use core::marker::PhantomData;
22
use core::mem;
3+
use core::mem::size_of;
34
use core::ptr;
45
use core::ptr::NonNull;
56
use core::slice;
@@ -56,14 +57,35 @@ struct NSFastEnumerationState<T: INSObject> {
5657
extra: [c_ulong; 5],
5758
}
5859

60+
/// Ideally the encoding of `long` would just be the same as `int` when it's
61+
/// 32 bits wide and the same as `long long` when it's 64 bits wide; then
62+
/// `c_long::ENCODING` would just work.
63+
///
64+
/// Unfortunately, `long` and `unsigned long` have a different encoding than
65+
/// `int` when it's 32 bits wide; the 'l'/'L' encoding.
66+
const U_LONG_ENCODING: Encoding<'static> = {
67+
// We could also just have used:
68+
// #[cfg(any(target_pointer_width = "32", windows))]
69+
//
70+
// But this way we exactly match what `clang` does:
71+
// https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/AST/ASTContext.cpp#L7245
72+
if size_of::<c_ulong>() == 4 {
73+
// @encode(unsigned long) = 'L'
74+
Encoding::ULong
75+
} else {
76+
// @encode(unsigned long) = 'Q'
77+
Encoding::ULongLong
78+
}
79+
};
80+
5981
unsafe impl<T: INSObject> Encode for NSFastEnumerationState<T> {
6082
const ENCODING: Encoding<'static> = Encoding::Struct(
6183
"?",
6284
&[
63-
c_ulong::ENCODING,
85+
U_LONG_ENCODING,
6486
Encoding::Pointer(&Encoding::Object), // <*const *const T>::ENCODING
65-
Encoding::Pointer(&c_ulong::ENCODING),
66-
Encoding::Array(5, &c_ulong::ENCODING),
87+
Encoding::Pointer(&U_LONG_ENCODING),
88+
Encoding::Array(5, &U_LONG_ENCODING),
6789
],
6890
);
6991
}

objc2/src/exception.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ mod tests {
128128
}
129129

130130
#[test]
131+
// TODO: `NULL` exceptions are invalid on 32-bit / w. fragile runtime
132+
#[cfg(not(all(target_os = "macos", target_arch = "x86")))]
131133
fn test_throw_catch_none() {
132134
let s = "Hello".to_string();
133135
let result = unsafe {

0 commit comments

Comments
 (0)