diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7f3a0c33..f0649bfc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,11 +1,17 @@ name: Rust -on: [push, pull_request] +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] jobs: build: - + strategy: + matrix: + ci-action: [bundle, dinghy] runs-on: macOS-latest steps: - uses: actions/cache@v2 @@ -25,24 +31,26 @@ jobs: toolchain: stable target: x86_64-apple-ios - - name: install clang - run: brew install llvm + - name: Install LLVM and Clang + uses: KyleMayes/install-llvm-action@v1.5.0 + with: + version: "13.0" - uses: actions/checkout@v1 - uses: actions-rs/install@v0.1 + if: ${{ matrix.ci-action == 'dinghy' }} with: crate: cargo-dinghy version: latest - - name: install cargo-bundle - run: cargo install cargo-bundle --git https://github.com/burtonageo/cargo-bundle.git - name: run cargo-dinghy - run: | - make test + if: ${{ matrix.ci-action == 'dinghy' }} + run: make test - - name: Build - run: cargo build --verbose --target x86_64-apple-ios + - name: install cargo-bundle + if: ${{ matrix.ci-action == 'bundle' }} + run: cargo install cargo-bundle --git https://github.com/burtonageo/cargo-bundle.git - name: Run cargo-bundle - run: | - make bundle-run + if: ${{ matrix.ci-action == 'bundle' }} + run: make bundle-run diff --git a/Cargo.toml b/Cargo.toml index da4878fd..a49f7ed1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ cargo-bundle's support for bundling crate examples. [build-dependencies] -bindgen = { version = "0.59.2", default-features = false } +bindgen = { version = "0.59.2", default-features = false} [target.'cfg(target_os = "ios")'.dependencies] objc = "0.2.7" diff --git a/Makefile b/Makefile index f9106206..c38f5b78 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ test: boot-sim bundle: cargo bundle --example rect --format ios --target $(TARGET) -bundle-install: bundle +bundle-install: bundle boot-sim xcrun simctl install booted target/$(TARGET)/debug/examples/bundle/ios/rect.app bundle-run: bundle-install diff --git a/build.rs b/build.rs index 90b91b75..8ec751a7 100644 --- a/build.rs +++ b/build.rs @@ -60,16 +60,16 @@ fn build(sdk_path: Option<&str>, target: &str) { builder = builder .clang_args(&clang_args) .objc_extern_crate(true) - .block_extern_crate(true) - .generate_block(true) + //.block_extern_crate(true) + //.generate_block(true) .rustfmt_bindings(true) // time.h as has a variable called timezone that conflicts with some of the objective-c // calls from NSCalendar.h in the Foundation framework. This removes that one variable. - .blacklist_item("timezone") + .blocklist_item("timezone") // https://github.com/rust-lang/rust-bindgen/issues/1705 - .blacklist_item("IUIStepper") - .blacklist_function("dividerImageForLeftSegmentState_rightSegmentState_") - .blacklist_item("objc_object") + .blocklist_item("IUIStepper") + .blocklist_function("dividerImageForLeftSegmentState_rightSegmentState_") + .blocklist_item("objc_object") .header_contents("UIKit.h", "#include"); // Generate the bindings. diff --git a/examples/rect.rs b/examples/rect.rs index 02c3c039..a4fc681b 100644 --- a/examples/rect.rs +++ b/examples/rect.rs @@ -1,17 +1,18 @@ -#[macro_use] extern crate objc; +#[macro_use] +extern crate objc; +use log::trace; +use objc::{ + declare::ClassDecl, + runtime::{Class, Object, Sel}, +}; +use winit::event_loop::EventLoopProxy; use winit::{ event::{Event, StartCause, WindowEvent}, event_loop::{ControlFlow, EventLoop}, platform::ios::{EventLoopExtIOS, WindowBuilderExtIOS, WindowExtIOS}, window::{Window, WindowBuilder}, }; -use objc::{ - declare::ClassDecl, - runtime::{Class, Object, Sel}, -}; -use log::trace; -use winit::event_loop::EventLoopProxy; use objc::msg_send; use uikit_sys::CFGetRetainCount; @@ -53,7 +54,6 @@ pub fn main() -> ! { let root_view: UIView = UIView(window.ui_view() as id); unsafe { - //let background = UIColor::alloc().initWithRed_green_blue_alpha_(0.1, 1.0, 2.0, 2.0); let background = UIColor::redColor(); root_view.setBackgroundColor_(background); } @@ -61,45 +61,50 @@ pub fn main() -> ! { let mut label = add_counte_label(count); event_loop.run( move |event: winit::event::Event, _, control_flow| { - *control_flow = ControlFlow::Wait; + *control_flow = ControlFlow::Wait; - match event { - Event::NewEvents(StartCause::Init) => { - let root_view: UIView = UIView(window.ui_view() as id); - //add_views(&root_view); - unsafe { - root_view.addSubview_(label.clone()); - } - } - Event::LoopDestroyed => return, - Event::RedrawRequested(_) => {} - Event::WindowEvent { ref event, .. } => match event { - WindowEvent::Resized(_logical_size) => { - //window.request_redraw(); - } - WindowEvent::Touch(winit::event::Touch { phase, .. }) => { - if phase == &winit::event::TouchPhase::Started { - println!("Removing old label"); - //for i in 1..100 { - unsafe { - label.removeFromSuperview(); - } - count = count + 1; - label = add_counte_label(count); + match event { + Event::NewEvents(StartCause::Init) => { + let root_view: UIView = UIView(window.ui_view() as id); + let views = get_views(); + for i in &views { unsafe { - root_view.addSubview_(label.clone()); + root_view.addSubview_(i.clone()); } } - //} + unsafe { + root_view.addSubview_(label.clone()); + } } - WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, - _ => (), - }, - Event::UserEvent(widget_event) => { + Event::LoopDestroyed => return, + Event::RedrawRequested(_) => {} + Event::WindowEvent { ref event, .. } => match event { + WindowEvent::Resized(_logical_size) => { + //window.request_redraw(); + } + WindowEvent::Touch(winit::event::Touch { phase, .. }) => { + if phase == &winit::event::TouchPhase::Started { + println!("Removing old label"); + //for i in 1..100 { + unsafe { + label.removeFromSuperview(); + } + count = count + 1; + label = add_counte_label(count); + unsafe { + root_view.addSubview_(label.clone()); + } + } + //} + } + WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, + _ => (), + }, + Event::UserEvent(widget_event) => {} + _ => {} } - _ => {} - } - }) + }, + ) } #[derive(PartialEq, Clone, Debug)] @@ -178,7 +183,9 @@ impl EventHandler { } } -fn add_views(root_view: &UIView) {//{{{ +fn get_views() -> Vec { + //{{{ + let mut views = Vec::new(); let rect = CGRect { origin: CGPoint { x: 10.0, y: 20.0 }, size: CGSize { @@ -192,9 +199,7 @@ fn add_views(root_view: &UIView) {//{{{ foo.setBackgroundColor_(background); foo }; - unsafe { - root_view.addSubview_(rect); - } + views.push(rect); let input_rect = CGRect { origin: CGPoint { x: 10.0, y: 50.0 }, size: CGSize { @@ -204,7 +209,7 @@ fn add_views(root_view: &UIView) {//{{{ }; let input = unsafe { let text_container = NSTextContainer(NSTextContainer::alloc().initWithSize_(CGSize { - height: 10.0, + height: 100.0, width: 200.0, })); let foo = UITextView( @@ -212,11 +217,9 @@ fn add_views(root_view: &UIView) {//{{{ ); foo }; - unsafe { - root_view.addSubview_(UIView(input.0)); - } - unsafe { - let switch = UISwitch(uikit_sys::IUISwitch::initWithFrame_( + views.push(UIView(input.0)); + let switch = unsafe { + UISwitch(uikit_sys::IUISwitch::initWithFrame_( &UISwitch::alloc(), CGRect { origin: CGPoint { x: 10.0, y: 80.0 }, @@ -225,12 +228,14 @@ fn add_views(root_view: &UIView) {//{{{ width: 200.0, }, }, - )); - root_view.addSubview_(UIView(switch.0)); - } -}//}}} + )) + }; + views.push(UIView(switch.0)); + views +} //}}} -fn add_counte_label(count: i64) -> UIView {//{{{ +fn add_counte_label(count: i64) -> UIView { + //{{{ use uikit_sys::{ CGPoint, CGRect, CGSize, INSObject, IUILabel, NSString, NSString_NSStringExtensionMethods, NSUTF8StringEncoding, UILabel, UIView_UIViewGeometry, UIView_UIViewHierarchy, @@ -268,7 +273,7 @@ fn add_counte_label(count: i64) -> UIView {//{{{ }; //label UIView(label.0) -}//}}} +} //}}} fn debug_init() { color_backtrace::install_with_settings(