Skip to content

Commit

Permalink
Use github action to install llvm (#3)
Browse files Browse the repository at this point in the history
* Use github action to install llvm
* Fix ci
  • Loading branch information
simlay authored Jan 23, 2022
1 parent 76b3b94 commit 9e108fc
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 77 deletions.
32 changes: 20 additions & 12 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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/[email protected]
with:
version: "13.0"

- uses: actions/checkout@v1
- uses: actions-rs/[email protected]
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UIKit/UIKit.h>");

// Generate the bindings.
Expand Down
119 changes: 62 additions & 57 deletions examples/rect.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -53,53 +54,57 @@ 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);
}
let mut count = 0;
let mut label = add_counte_label(count);
event_loop.run(
move |event: winit::event::Event<WidgetEvent>, _, 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)]
Expand Down Expand Up @@ -178,7 +183,9 @@ impl EventHandler {
}
}

fn add_views(root_view: &UIView) {//{{{
fn get_views() -> Vec<UIView> {
//{{{
let mut views = Vec::new();
let rect = CGRect {
origin: CGPoint { x: 10.0, y: 20.0 },
size: CGSize {
Expand All @@ -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 {
Expand All @@ -204,19 +209,17 @@ 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(
UITextView::alloc().initWithFrame_textContainer_(input_rect, text_container),
);
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 },
Expand All @@ -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,
Expand Down Expand Up @@ -268,7 +273,7 @@ fn add_counte_label(count: i64) -> UIView {//{{{
};
//label
UIView(label.0)
}//}}}
} //}}}

fn debug_init() {
color_backtrace::install_with_settings(
Expand Down

0 comments on commit 9e108fc

Please sign in to comment.