Skip to content

Fix CI setup #5

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

Merged
merged 16 commits into from
Aug 31, 2021
Merged
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
125 changes: 125 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: CI

on:
push:
branches: [master]
pull_request:

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
# Faster compilation and error on warnings
RUSTFLAGS: "-C debuginfo=0 -D warnings"

jobs:
fmt:
name: Check formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check

test:
name: Test
strategy:
matrix:
platform:
- { os: ubuntu-latest } # TODO: 32bit and gcc-multilib
- { os: macos-10.15 }
- { os: macos-11 }
# - { target: x86_64-apple-ios, os: macos-latest, }
# - { target: aarch64-apple-ios, os: macos-latest, }

runs-on: ${{ matrix.platform.os }}

steps:
- uses: actions/checkout@v2

- name: Cache Rust
uses: actions/cache@v2
with:
path: |
~/.cargo/
target/
key: ${{ matrix.platform.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ matrix.platform.os }}-cargo-

- name: Install Packages
if: contains(matrix.platform.os, 'ubuntu')
run: sudo apt-get install gobjc clang make

- name: Install different Rust toolchain
# A default toolchain is already installed
if: matrix.platform.target
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.platform.target }}
profile: minimal
override: true

- name: Check documentation
uses: actions-rs/cargo@v1
with:
# TODO: Disallow warnings here
command: doc
args: --no-deps --document-private-items

- # Run before we install GNUStep as a "fail fast" mechanism
name: Run checks
uses: actions-rs/cargo@v1
with:
command: check
args: --verbose

- name: Install GNUStep libobjc2
if: contains(matrix.platform.os, 'ubuntu')
run: |
wget https://github.com/gnustep/libobjc2/archive/refs/tags/v1.9.tar.gz
tar -xzf v1.9.tar.gz
mkdir libobjc2-1.9/build
cd libobjc2-1.9/build
export CC="clang"
export CXX="clang++"
cmake ../
sudo make install

- name: Install GNUStep make
if: contains(matrix.platform.os, 'ubuntu')
run: |
wget https://github.com/gnustep/tools-make/archive/refs/tags/make-2_9_0.tar.gz
tar -xzf make-2_9_0.tar.gz
cd tools-make-make-2_9_0
./configure --with-library-combo=ng-gnu-gnu
sudo make install

- name: Install GNUStep-Base
if: contains(matrix.platform.os, 'ubuntu')
run: |
wget https://github.com/gnustep/libs-base/archive/refs/tags/base-1_28_0.tar.gz
tar -xzf base-1_28_0.tar.gz
cd libs-base-base-1_28_0
./configure --disable-tls
sudo make install

- name: Setup environment
if: contains(matrix.platform.os, 'ubuntu')
run: |
ls -al /usr/local/lib
ls -al /usr/local/include
echo "LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
echo "CPATH=/usr/local/include:$CPATH" >> $GITHUB_ENV

- name: Build and run tests
uses: actions-rs/cargo@v1
with:
command: test
# TODO: `objc/exception` feature is broken in objc_foundation
# TODO: `objc_foundation/block` feature doesn't work on GNUStep
args: --verbose --no-fail-fast --no-default-features
45 changes: 45 additions & 0 deletions .travis-disabled.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
sudo: false
language: rust
cache: cargo
os: osx

# Run on master and PRs
if: branch = master

script:
- cargo test --workspace --verbose
- # TODO: cargo test --workspace --verbose --all-features

jobs:
include:
- name: MacOS 10.11
osx_image: xcode7.3

- name: MacOS 10.13 (with 32bit)
osx_image: xcode9.4
rust: nightly
# 32-bit targets only have tier 3 support
install: rustup component add rust-src
script:
- cargo test --workspace --verbose
- # TODO: cargo test --workspace --verbose --all-features
- # objc_exception doesn't work on 32bit?
cargo test --workspace --exclude objc_exception --verbose -Z build-std --target i686-apple-darwin
- # TODO: cargo test --workspace --verbose --all-features -Z build-std --target i686-apple-darwin

- name: MacOS 11.3
osx_image: xcode12.5

- name: iOS nightly
osx_image: xcode7.3
rust: nightly
before_install: rustup component add rust-src
# Install rust-test-ios
install: curl -LO https://github.com/SSheldon/rust-test-ios/releases/download/0.1.1/rust-test-ios && chmod +x rust-test-ios
before_script:
# Enable -Z build-std, 32-bit targets only have tier 3 support
- printf '[unstable]\nbuild-std = ["std"]\n' > $HOME/.cargo/config.toml
# Remove workspace since `rust-test-ios` is not made for that
- rm Cargo.toml
# TODO: env: FEATURES="exception"
script: cd objc && ../rust-test-ios
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ members = [
"objc_foundation",
"objc_id",
]
exclude = ["objc/tests-ios"]
31 changes: 0 additions & 31 deletions objc/.travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions objc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ exclude = [
".gitignore",
".travis.yml",
"doc.sh",
"travis_install.sh",
"travis_test.sh",
"tests-ios/**",
]

Expand Down
3 changes: 3 additions & 0 deletions objc/tests-ios/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[macro_use]
extern crate objc;

use objc::rc::*;
use objc::runtime::*;
pub use objc::*;
Expand Down
26 changes: 0 additions & 26 deletions objc/travis_install.sh

This file was deleted.

10 changes: 0 additions & 10 deletions objc/travis_test.sh

This file was deleted.

1 change: 1 addition & 0 deletions objc_exception/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fn main() {
cc::Build::new()
.file("extern/exception.m")
.flag("-fobjc-exceptions")
.compile("libexception.a");
}
13 changes: 5 additions & 8 deletions objc_exception/extern/exception.m
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#include <objc/objc.h>
#include <objc/NSObject.h>

void RustObjCExceptionThrow(id exception) {
@throw exception;
}
// Always available in Objective-C
// See https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain
id objc_retain(id value);

int RustObjCExceptionTryCatch(void (*try)(void *), void *context, id *error) {
@try {
try(context);
if (error) {
*error = nil;
*error = (id)0; // nil
}
return 0;
} @catch (id exception) {
if (error) {
*error = [exception retain];
*error = objc_retain(exception);
}
return 1;
}
Expand Down
20 changes: 16 additions & 4 deletions objc_exception/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ use std::os::raw::{c_int, c_void};
use std::ptr;

#[link(name = "objc", kind = "dylib")]
extern "C" {}
// TODO: "C-unwind"
extern "C" {
/// See [`objc-exception.h`][objc-exception].
///
/// [objc-exception]: https://opensource.apple.com/source/objc4/objc4-818.2/runtime/objc-exception.h.auto.html
// Header marks this with _Nonnull, but LLVM output shows otherwise
fn objc_exception_throw(exception: *mut c_void) -> !;
// fn objc_exception_rethrow();
}

extern "C" {
fn RustObjCExceptionThrow(exception: *mut c_void);
fn RustObjCExceptionTryCatch(
r#try: extern "C" fn(*mut c_void),
context: *mut c_void,
Expand All @@ -26,9 +33,14 @@ pub enum Exception {}
///
/// This unwinds from Objective-C, and the exception must be caught using an
/// Objective-C exception handler.
///
/// This also invokes undefined behaviour until `C-unwind` is stabilized, see
/// [RFC-2945].
///
/// [RFC-2945]: https://rust-lang.github.io/rfcs/2945-c-unwind-abi.html
#[inline]
pub unsafe fn throw(exception: *mut Exception) -> ! {
RustObjCExceptionThrow(exception as *mut _);
unreachable!();
objc_exception_throw(exception as *mut _)
}

unsafe fn try_no_ret<F>(closure: F) -> Result<(), *mut Exception>
Expand Down
5 changes: 4 additions & 1 deletion objc_foundation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ license = "MIT"

exclude = [".gitignore"]

[features]
default = ["block"]

[dependencies]
block = "0.1"
block = { optional = true, version = "0.1" }
objc = { path = "../objc", version = "0.2.7" }
objc_id = { path = "../objc_id", version = "0.1" }
6 changes: 4 additions & 2 deletions objc_foundation/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::mem;
use std::ops::Range;
use std::os::raw::c_void;
use std::slice;

use super::{INSCopying, INSMutableCopying, INSObject, NSRange};
#[cfg(feature = "block")]
use block::{Block, ConcreteBlock};
use objc::msg_send;
use objc_id::Id;
Expand Down Expand Up @@ -39,6 +39,7 @@ pub trait INSData: INSObject {
}
}

#[cfg(feature = "block")]
fn from_vec(bytes: Vec<u8>) -> Id<Self> {
let capacity = bytes.capacity();
let dealloc = ConcreteBlock::new(move |bytes: *mut c_void, len: usize| unsafe {
Expand All @@ -56,7 +57,7 @@ pub trait INSData: INSObject {
let obj: *mut Self = msg_send![obj, initWithBytesNoCopy:bytes_ptr
length:bytes.len()
deallocator:dealloc];
mem::forget(bytes);
std::mem::forget(bytes);
Id::from_retained_ptr(obj)
}
}
Expand Down Expand Up @@ -192,6 +193,7 @@ mod tests {
assert!(data.bytes() == [8, 17]);
}

#[cfg(feature = "block")]
#[test]
fn test_from_vec() {
let bytes = vec![3, 7, 16];
Expand Down
Loading