Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiling for iOS #46

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ jobs:
with:
command: build
args: --features webview --example webview_custom_protocol
# fails because it needs uikit, which is not
# building for me
#- uses: actions-rs/cargo@v1
# with:
# command: build
# args: --example ios-beta
# Since it's all Objective-C message passing under the hood, we're
# really just looking for whether we've broken the iOS build. It is likely
# that more robust tests/checking infrastructure should exist for this side
# of things as the iOS portion gets iterated on.
#
# (e.g, this at the moment will not catch invalid selector calls, like if an appkit-specific
# selector is used for something on iOS)
- uses: actions-rs/cargo@v1
with:
command: build
target: x86_64-apple-ios
args: --example ios-beta --no-default-features --features uikit,autolayout
Comment on lines +68 to +72
Copy link
Contributor

@simlay simlay Aug 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell, the build error you got in CI is the same as what I got when I ran cargo build --example ios-beta --no-default-features --features uikit,autolayout (notice the lack of --target x86_64-apple-ios). I think it needs to be done in the args section similar to how the use-cross section of the actions-rs/cargo` references.

2 changes: 1 addition & 1 deletion examples/ios-beta/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Since this needs to run in an iOS simulator or on a device, you can't run it lik
- Start a simulator (Simulator.app).
- `cargo install cargo-bundle`
- `cargo bundle --example ios-beta --no-default-features --features uikit,autolayout --target x86_64-apple-ios`
Copy link
Contributor

@simlay simlay Aug 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add this to CI in a new github job?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably makes sense to do so, yeah - that way we'll know if I break it again ;)

- `xcrun simctl install booted target/x86_64-apple-ios/debug/examples/bundle/ios/cacao-ios-beta.app`
- `xcrun simctl install booted target/x86_64-apple-ios/debug/examples/bundle/ios/ios-beta.app`
- `xcrun simctl launch --console booted com.cacao.ios-test`

## Current Support
Expand Down
7 changes: 7 additions & 0 deletions src/layout/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use objc_id::ShareId;

use crate::foundation::{id, NO, YES};

#[cfg(all(feature = "appkit", target_os = "macos"))]
use super::LayoutConstraintAnimatorProxy;

/// A wrapper for `NSLayoutConstraint`. This both acts as a central path through which to activate
Expand All @@ -31,14 +32,18 @@ pub struct LayoutConstraint {
pub priority: f64,

/// An animator proxy that can be used inside animation contexts.
/// This is currently only supported on macOS with the `appkit` feature.
#[cfg(all(feature = "appkit", target_os = "macos"))]
pub animator: LayoutConstraintAnimatorProxy
}

impl LayoutConstraint {
/// An internal method for wrapping existing constraints.
pub(crate) fn new(object: id) -> Self {
LayoutConstraint {
#[cfg(all(feature = "appkit", target_os = "macos"))]
animator: LayoutConstraintAnimatorProxy::new(object),

constraint: unsafe { ShareId::from_ptr(object) },
offset: 0.0,
multiplier: 0.0,
Expand All @@ -55,7 +60,9 @@ impl LayoutConstraint {
}

LayoutConstraint {
#[cfg(all(feature = "appkit", target_os = "macos"))]
animator: self.animator,

constraint: self.constraint,
offset: offset,
multiplier: self.multiplier,
Expand Down
3 changes: 3 additions & 0 deletions src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
mod traits;
pub use traits::Layout;

#[cfg(all(feature = "appkit", target_os = "macos"))]
mod animator;

#[cfg(all(feature = "appkit", target_os = "macos"))]
pub use animator::LayoutConstraintAnimatorProxy;

#[cfg(feature = "autolayout")]
Expand Down
9 changes: 9 additions & 0 deletions src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ use crate::layout::{LayoutAnchorDimension, LayoutAnchorX, LayoutAnchorY, SafeAre
#[cfg(feature = "appkit")]
use crate::pasteboard::PasteboardType;

#[cfg(all(feature = "appkit", target_os = "macos"))]
mod animator;

#[cfg(all(feature = "appkit", target_os = "macos"))]
pub use animator::ViewAnimatorProxy;

#[cfg_attr(feature = "appkit", path = "appkit.rs")]
Expand Down Expand Up @@ -94,6 +97,9 @@ pub struct View<T = ()> {
pub objc: ObjcProperty,

/// An object that supports limited animations. Can be cloned into animation closures.
///
/// This is currently only supported on macOS with the `appkit` feature.
#[cfg(all(feature = "appkit", target_os = "macos"))]
pub animator: ViewAnimatorProxy,

/// References the underlying layer. This is consistent across AppKit & UIKit - in AppKit
Expand Down Expand Up @@ -209,6 +215,7 @@ impl View {

layer: Layer::wrap(unsafe { msg_send![view, layer] }),

#[cfg(all(feature = "appkit", target_os = "macos"))]
animator: ViewAnimatorProxy::new(view),
objc: ObjcProperty::retain(view)
}
Expand Down Expand Up @@ -256,6 +263,8 @@ impl<T> View<T> {
is_handle: true,
layer: self.layer.clone(),
objc: self.objc.clone(),

#[cfg(all(feature = "appkit", target_os = "macos"))]
animator: self.animator.clone(),

#[cfg(feature = "autolayout")]
Expand Down