From 552021c0966020a9c3fcc9a404e41ab09df51f55 Mon Sep 17 00:00:00 2001 From: Aleksi Juvani Date: Thu, 22 Aug 2019 18:55:59 +0300 Subject: [PATCH] Fix i686-apple-darwin compile target --- .travis.yml | 41 +++++++++++++++------------------ cocoa/examples/fullscreen.rs | 2 +- cocoa/src/foundation.rs | 20 ++++++++-------- cocoa/tests/foundation.rs | 22 +++++++++++------- core-foundation-sys/src/base.rs | 14 +++++------ core-foundation-sys/src/url.rs | 10 ++++---- core-graphics/src/event.rs | 2 +- io-surface/Cargo.toml | 2 -- 8 files changed, 56 insertions(+), 57 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0ce205a..04b87ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,29 +1,24 @@ +os: osx language: rust rust: stable matrix: include: - - os: osx # 10.12 - env: CGFEATURES="--features elcapitan" - - os: osx # 10.10 - osx_image: xcode7.2 - env: CGFEATURES="" - - os: osx # 10.13 - osx_image: xcode9.4 - env: CGFEATURES="--features highsierra,elcapitan" + # macOS 10.12 + - env: TARGET=x86_64-apple-darwin CGFEATURES="--features elcapitan" + - env: TARGET=i686-apple-darwin CGFEATURES="--features elcapitan" + # macOS 10.10 + - osx_image: xcode7.2 + env: TARGET=x86_64-apple-darwin CGFEATURES="" + - osx_image: xcode7.2 + env: TARGET=i686-apple-darwin CGFEATURES="" + # macOS 10.13 + - osx_image: xcode9.4 + env: TARGET=x86_64-apple-darwin CGFEATURES="--features highsierra,elcapitan" + - osx_image: xcode9.4 + env: TARGET=i686-apple-darwin CGFEATURES="--features highsierra,elcapitan" +install: + - rustup target add $TARGET script: - - cd core-foundation - - cargo build --verbose - - cargo test --verbose -- --nocapture - - cd ../core-graphics - - cargo build --verbose $CGFEATURES - - cargo test --verbose $CGFEATURES -- --nocapture - - cd ../core-text - - cargo build --verbose - - cargo test --verbose -- --nocapture - - cd ../cocoa - - cargo build --verbose - - cargo test --verbose -- --nocapture - - cd ../io-surface - - cargo build --verbose - - cargo test --verbose -- --nocapture + - cargo build --all-targets --verbose --target $TARGET + - cargo test --verbose --target $TARGET -- --nocapture diff --git a/cocoa/examples/fullscreen.rs b/cocoa/examples/fullscreen.rs index df09d57..c826a29 100644 --- a/cocoa/examples/fullscreen.rs +++ b/cocoa/examples/fullscreen.rs @@ -76,7 +76,7 @@ fn main() { // create Window let display = CGDisplay::main(); - let size = NSSize::new(display.pixels_wide() as f64, display.pixels_high() as f64); + let size = NSSize::new(display.pixels_wide() as _, display.pixels_high() as _); let window = NSWindow::alloc(nil) .initWithContentRect_styleMask_backing_defer_(NSRect::new(NSPoint::new(0., 0.), size), NSWindowStyleMask::NSTitledWindowMask, diff --git a/cocoa/src/foundation.rs b/cocoa/src/foundation.rs index ffc1ee9..d87c446 100644 --- a/cocoa/src/foundation.rs +++ b/cocoa/src/foundation.rs @@ -42,13 +42,13 @@ mod macos { #[repr(C)] #[derive(Copy, Clone)] pub struct NSPoint { - pub x: f64, - pub y: f64, + pub x: CGFloat, + pub y: CGFloat, } impl NSPoint { #[inline] - pub fn new(x: f64, y: f64) -> NSPoint { + pub fn new(x: CGFloat, y: CGFloat) -> NSPoint { NSPoint { x: x, y: y, @@ -59,8 +59,8 @@ mod macos { unsafe impl objc::Encode for NSPoint { fn encode() -> objc::Encoding { let encoding = format!("{{CGPoint={}{}}}", - f64::encode().as_str(), - f64::encode().as_str()); + CGFloat::encode().as_str(), + CGFloat::encode().as_str()); unsafe { objc::Encoding::from_str(&encoding) } } } @@ -68,13 +68,13 @@ mod macos { #[repr(C)] #[derive(Copy, Clone)] pub struct NSSize { - pub width: f64, - pub height: f64, + pub width: CGFloat, + pub height: CGFloat, } impl NSSize { #[inline] - pub fn new(width: f64, height: f64) -> NSSize { + pub fn new(width: CGFloat, height: CGFloat) -> NSSize { NSSize { width: width, height: height, @@ -85,8 +85,8 @@ mod macos { unsafe impl objc::Encode for NSSize { fn encode() -> objc::Encoding { let encoding = format!("{{CGSize={}{}}}", - f64::encode().as_str(), - f64::encode().as_str()); + CGFloat::encode().as_str(), + CGFloat::encode().as_str()); unsafe { objc::Encoding::from_str(&encoding) } } } diff --git a/cocoa/tests/foundation.rs b/cocoa/tests/foundation.rs index b62710d..219a3b9 100644 --- a/cocoa/tests/foundation.rs +++ b/cocoa/tests/foundation.rs @@ -148,14 +148,20 @@ mod foundation { // sorted iterators to ensure that each item is the same as its counterpart in // the vector. + fn compare_function(s0: &id, s1: &id) -> Ordering { + unsafe { + let (bytes0, len0) = (s0.UTF8String() as *const u8, s0.len()); + let (bytes1, len1) = (s1.UTF8String() as *const u8, s1.len()); + let (s0, s1) = (str::from_utf8(slice::from_raw_parts(bytes0, len0)).unwrap(), + str::from_utf8(slice::from_raw_parts(bytes1, len1)).unwrap()); + let (c0, c1) = (s0.chars().next().unwrap(), s1.chars().next().unwrap()); + c0.cmp(&c1) + } + } + // First test cocoa sorting... let mut comparator = ConcreteBlock::new(|s0: id, s1: id| { - let (bytes0, len0) = (s0.UTF8String() as *const u8, s0.len()); - let (bytes1, len1) = (s1.UTF8String() as *const u8, s1.len()); - let (s0, s1) = (str::from_utf8(slice::from_raw_parts(bytes0, len0)).unwrap(), - str::from_utf8(slice::from_raw_parts(bytes1, len1)).unwrap()); - let (c0, c1) = (s0.chars().next().unwrap(), s1.chars().next().unwrap()); - match c0.cmp(&c1) { + match compare_function(&s0, &s1) { Ordering::Less => NSComparisonResult::NSOrderedAscending, Ordering::Equal => NSComparisonResult::NSOrderedSame, Ordering::Greater => NSComparisonResult::NSOrderedDescending, @@ -173,13 +179,13 @@ mod foundation { // Then use rust sorting let mut keys_arr = dict.allKeys().iter().collect::>(); - keys_arr.sort(); + keys_arr.sort_by(compare_function); for (k0, k1) in keys_arr.into_iter().zip(keys.iter()) { assert!(k0.isEqualToString(k1)); } let mut objects_arr = dict.allValues().iter().collect::>(); - objects_arr.sort(); + objects_arr.sort_by(compare_function); for (v0, v1) in objects_arr.into_iter().zip(objects.iter()) { assert!(v0.isEqualToString(v1)); } diff --git a/core-foundation-sys/src/base.rs b/core-foundation-sys/src/base.rs index 8cbae38..3abed34 100644 --- a/core-foundation-sys/src/base.rs +++ b/core-foundation-sys/src/base.rs @@ -8,23 +8,23 @@ // except according to those terms. use std::cmp::Ordering; -use std::os::raw::{c_uint, c_long, c_ulong, c_void, c_int}; +use std::os::raw::{c_uint, c_void, c_int}; use string::CFStringRef; pub type Boolean = u8; -pub type CFIndex = c_long; pub type mach_port_t = c_uint; pub type CFAllocatorRef = *const c_void; pub type CFNullRef = *const c_void; -pub type CFHashCode = c_ulong; -pub type CFTypeID = c_ulong; pub type CFTypeRef = *const c_void; -pub type CFOptionFlags = u32; pub type OSStatus = i32; pub type SInt32 = c_int; +pub type CFTypeID = usize; +pub type CFOptionFlags = usize; +pub type CFHashCode = usize; +pub type CFIndex = isize; -#[repr(i64)] -#[derive(Clone, Copy)] +#[repr(isize)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum CFComparisonResult { LessThan = -1, EqualTo = 0, diff --git a/core-foundation-sys/src/url.rs b/core-foundation-sys/src/url.rs index e5e699d..08e7bcd 100644 --- a/core-foundation-sys/src/url.rs +++ b/core-foundation-sys/src/url.rs @@ -33,15 +33,15 @@ pub const kCFURLHFSPathStyle: CFURLPathStyle = 1; pub const kCFURLWindowsPathStyle: CFURLPathStyle = 2; pub static kCFURLBookmarkCreationPreferFileIDResolutionMask: CFURLBookmarkCreationOptions = - (1 << 8) as u32; + (1u32 << 8) as usize; pub static kCFURLBookmarkCreationMinimalBookmarkMask: CFURLBookmarkCreationOptions = - (1 << 9) as u32; + (1u32 << 9) as usize; pub static kCFURLBookmarkCreationSuitableForBookmarkFile: CFURLBookmarkCreationOptions = - (1 << 10) as u32; + (1u32 << 10) as usize; pub static kCFURLBookmarkCreationWithSecurityScope: CFURLBookmarkCreationOptions = - (1 << 11) as u32; + (1u32 << 11) as usize; pub static kCFURLBookmarkCreationSecurityScopeAllowOnlyReadAccess: CFURLBookmarkCreationOptions = - (1 << 12) as u32; + (1u32 << 12) as usize; // TODO: there are a lot of missing keys and constants. Add if you are bored or need them. diff --git a/core-graphics/src/event.rs b/core-graphics/src/event.rs index cab7378..770ca08 100644 --- a/core-graphics/src/event.rs +++ b/core-graphics/src/event.rs @@ -105,7 +105,7 @@ impl ScrollEventUnit { /// Constants that specify the different types of input events. /// /// [Ref](http://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-700/IOHIDSystem/IOKit/hidsystem/IOLLEvent.h) -#[repr(C)] +#[repr(u32)] #[derive(Clone, Copy, Debug)] pub enum CGEventType { Null = 0, diff --git a/io-surface/Cargo.toml b/io-surface/Cargo.toml index 0afb0c8..11e8b90 100644 --- a/io-surface/Cargo.toml +++ b/io-surface/Cargo.toml @@ -10,8 +10,6 @@ license = "MIT / Apache-2.0" [dependencies] libc = "0.2" gleam = "0.6" - -[target.x86_64-apple-darwin.dependencies] core-foundation = { path = "../core-foundation", version = "0.6" } cgl = "0.2.3" leaky-cow = "0.1.1"