Giter Club home page Giter Club logo

cocoa-rs's Introduction

The Servo Parallel Browser Engine Project

Servo is a prototype web browser engine written in the Rust language. It is currently developed on 64-bit macOS, 64-bit Linux, 64-bit Windows, and Android.

Servo welcomes contribution from everyone. Check out The Servo Book to get started, or go to servo.org for news and guides.

Getting started

For more detailed build instructions, see the Servo book under Setting up your environment, Building Servo, and Building for Android.

macOS

  • Download and install python, Xcode, and brew
  • Install rustup: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • Restart your shell to make sure cargo is available
  • Install the other dependencies: ./mach bootstrap
  • Build servoshell: ./mach build

Linux

  • Install curl and python:
    • Arch: sudo pacman -S --needed curl python python-pip
    • Debian, Ubuntu: sudo apt install curl python3-pip python3-venv
    • Fedora: sudo dnf install curl python3 python3-pip python3-devel
    • Gentoo: sudo emerge net-misc/curl dev-python/pip
  • Install rustup: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • Restart your shell to make sure cargo is available
  • Install the other dependencies: ./mach bootstrap
  • Build servoshell: ./mach build

Windows

  • Download and install python, choco, and rustup
    • Be sure to select Quick install via the Visual Studio Community installer
  • In the Visual Studio Installer, ensure the following components are installed:
    • Windows 10 SDK (10.0.19041.0) (Microsoft.VisualStudio.Component.Windows10SDK.19041)
    • MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest) (Microsoft.VisualStudio.Component.VC.Tools.x86.x64)
    • C++ ATL for latest v143 build tools (x86 & x64) (Microsoft.VisualStudio.Component.VC.ATL)
    • C++ MFC for latest v143 build tools (x86 & x64) (Microsoft.VisualStudio.Component.VC.ATLMFC)
  • Restart your shell to make sure cargo is available
  • Install the other dependencies: .\mach bootstrap
  • Build servoshell: .\mach build

Android

  • Ensure that the following environment variables are set:
    • ANDROID_SDK_ROOT
    • ANDROID_NDK_ROOT: $ANDROID_SDK_ROOT/ndk/25.2.9519653/ ANDROID_SDK_ROOT can be any directory (such as ~/android-sdk). All of the Android build dependencies will be installed there.
  • Install the latest version of the Android command-line tools to $ANDROID_SDK_ROOT/cmdline-tools/latest.
  • Run the following command to install the necessary components:
    sudo $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --install
     "build-tools;33.0.2" \
     "emulator" \
     "ndk;25.2.9519653" \
     "platform-tools" \
     "platforms;android-33" \
     "system-images;android-33;google_apis;x86_64"
  • Follow the instructions above for the platform you are building on

cocoa-rs's People

Contributors

alexchandel avatar brendanzab avatar brson avatar burtonageo avatar codesmythe avatar eijebong avatar fkaa avatar frewsxcv avatar glennw avatar gw3583 avatar hnry avatar ivanukhov avatar jdm avatar kmcallister avatar larsbergstrom avatar mbrubeck avatar metajack avatar mitchmindtree avatar ms2ger avatar nox avatar oluseyi avatar paulrouget avatar pcwalton avatar rafaelbarbosa avatar ratake avatar sbward avatar simon-shopify avatar simonsapin avatar skylerlipthay avatar ssheldon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cocoa-rs's Issues

Why is this repository deprecated?

The README.md should be updated with a sentence or paragraph explaining just a little bit why this repository is deprecated (i.e., what is to replace it) and why abandon this repository’s approach to a projection of Objective C’s framework-API to Rust.

Allow creating custom NSColors

I was looking at the code and only found clearColor. However, I'd like the ability to use custom colors (to change the title bar on OSX).

I can implement this probably if you point me in the right direction.

Elegant combining of multiple NSWindowStyleMasks

Getting started with cocoa-rs as an experienced Objective-C Cocoa developer, I tried to modify the example at https://github.com/servo/cocoa-rs/blob/master/examples/hello_world.rs with multiple window style masks, converting the combined value to NSUInteger:

// create Window
let windowStyleMask = NSTitledWindowMask|
                        NSClosableWindowMask|
                        NSMiniaturizableWindowMask|
                        NSResizableWindowMask|
                        NSUnifiedTitleAndToolbarWindowMask|
                        NSFullSizeContentViewWindowMask as NSUInteger;

let window = NSWindow::alloc(nil)
    .initWithContentRect_styleMask_backing_defer_(NSRect::new(NSPoint::new(0., 0.),
                                                                NSSize::new(200., 200.)),
                                                    windowStyleMask,
                                                    NSBackingStoreBuffered,
                                                    NO)

Of course, this didn't work. I feel that cocoa-rs should strive to offer idiomatic interfaces wherever possible, so I looked into the implementation and feel that an elegant approach that preserves strong type information is possible.

Assertion error with basic usage of NSStatusBar

https://developer.apple.com/reference/appkit/nsstatusbar/1530619-systemstatusbar?language=objc

extern crate cocoa;

use cocoa::appkit::NSStatusBar;
use cocoa::base::nil;

fn main() {
    unsafe {
        let _ = NSStatusBar::systemStatusBar(nil);
    }
}
> cargo run
   Compiling mac-menu-bar v0.1.0 (file:///Users/corey/dev/rust-mac-menu-bar)
    Finished debug [unoptimized + debuginfo] target(s) in 0.30 secs
     Running `target/debug/mac-menu-bar`
Assertion failed: (CGAtomicGet(&is_initialized)), function CGSConnectionByID, file Services/Connection/CGSConnection.c, line 127.

No menu bar for example code

I'm attempting to run the "hello world" example on OS X 10.10.5. It compiles and runs, resulting in a little window with a "Hello World!" title, but the menu bar doesn't appear: I still have the iTerm menu at the top of the screen. I can Cmd-Tab switch away from and back to the example, but the menu still doesn't appear.

Is this only known to work correctly on certain versions of OS X?

Lots of type misalignment building under stable-i686-apple-darwin

Seems a lot of assumptions are made about the widths of certain types that make many usages of the library throw errors when building for 32-bit. For example, nextEventMatchingMask_untilDate_inMode_dequeue_'s mask parameter takes an NSInteger (

unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self,
), but the bitflags that are meant to be used there are backed by a libc::c_ulonglong, which is not compatible in 32-bit builds.

This causes, for example, https://github.com/tomaka/glutin to fail to compile under 32-bit rust-windowing/glutin#803 at least, and there may be more errors lurking around in there that this causes.

Provide example(s)

I can't tell how to use this library to create a Cocoa GUI idiomatically. This is all I could piece together from the source and test code:

extern crate cocoa;

use cocoa::base::{nil, ObjCMethodCall};
use cocoa::appkit::{NSApp, NSRect, NSPoint, NSSize};

static NSApplicationActivationPolicyRegular: int = 0i;
static NSTitledWindowMask: int = 1i;
static NSBackingStoreBuffered: int = 2i;

fn main() {
    let app_name = "Hello World!";

    unsafe {
        let app = NSApp();
        app.send("setActivationPolicy:", (NSApplicationActivationPolicyRegular));

        let window = "NSWindow".send("alloc", ()).send(
            "initWithContentRect:styleMask:backing:defer:",
            (
                NSRect {
                    origin: NSPoint {x: 0., y: 0.},
                    size: NSSize {width: 200., height: 200.}
                },
                NSTitledWindowMask,
                NSBackingStoreBuffered,
                false
            )
        );
        window.send("cascadeTopLeftFromPoint:", (NSPoint {x: 20., y: 20.}));
        window.send("setTitle:", (app_name));
        window.send("makeKeyAndOrderFront:", (nil));

        app.send("activateIgnoringOtherApps:", (true));
        app.send("run", ());
    }
}

Document usage paradigms

E.g. inheritance, method overloading and other stuff that explicitly requires ObjC features, which obviously miss in the bindings.

Newtypes instead of monolithic id

Is there any reasoning for using traits and implementing them onto id rather than creating newtypes such as struct NSString(id)? I've been running into name collisions with the former a lot lately.

Crash!

My dead-simple application which depends on rust-cocoa crashes when I merge c4b1941. You can reproduce the error with simnalamburt/fate@ba2615e

glium-practice[19076:161627] +[NSOpenGLContext initWithFormat_shareContext:]: unrecognized selector sent to class 0x7fff7682a850

Go here to see the core dump. Sadly, I failed to print stacktrace.

Improve type safety

I realise that Objective-C is a very loosely typed language, but it might be easier to work with the API if we enforce some type safety:

pub struct id(libc::intptr_t);
pub const nil: id = id(0);

pub struct NSWindow(id);
pub struct NSString(id);
...

impl Deref<id> for NSWindow { fn deref(&self) -> &id { ... } }
impl Deref<id> for NSString { fn deref(&self) -> &id { ... } }
...

I came up against this when trying to implement invoke_msg_void_NSInteger on NSInteger in #36 because it overlapped with id. It would also improve the documentation.

Consider implementing `Drop` for `NSAutoreleasePool`?

Does it make sense to implement a Drop trait for NSAutoreleasePool, so it is called whenever NSAutoreleasePool goes out of scope. It turns out that if the user does not call NSAutoreleasePool::drain() / NSAutoreleasePool::release() manually, the memory will be leaked (by the way the examples from the repository do not call drain, release as well).

Automatic binding generation?

PyObjc (and possibly RubyCocoa?) use .fwinfo files to generate language bindings around Cocoa and similar objective C libraries:

https://bitbucket.org/ronaldoussoren/pyobjc/raw/6b74fc7e1ba0995038dc5c1f162d1fad860ff175/pyobjc-framework-Cocoa/metadata/raw.AppKit/x86_64-10.10.fwinfo

From what I can tell, PyObjC uses a tool called objective.metadata to generate these files:

https://bitbucket.org/ronaldoussoren/objective.metadata/src/bd0f1b994403?at=default

Has anyone thought about doing automatic binding generation for cocoa-rs? Anyone know of easy strategies?

How do I implement delegates?

Hi!

This is not really an issue (or maybe it is?), but how do I implement an NSApplicationDelegate for example, and assign it to NSApp so that I can start responding to events?

Automatic string conversion for NSString::init_str

It's a bit of a pain manually adding the C-style null-terminator to every slice that's passed into appkit::NSString::init_str. Can we take a cue from base::class and do this?

use std::ffi;

unsafe fn init_str(self, string: &str) -> id {
    let c_string = ffi::CString::from_slice(string.as_bytes());
    self.initWithUTF8String_(c_string.as_ptr())
}

Multiple definitions of `initWithFrame_`

I get the following error when attempting to call initWithFrame_:

error[E0034]: multiple applicable items in scope
  --> src/lib.rs:63:52
   |
63 |                 let text = NSTextField::alloc(nil).initWithFrame_(frame);
   |                                                    ^^^^^^^^^^^^^^ multiple `initWithFrame_` found
   |
   = note: candidate #1 is defined in an impl of the trait `cocoa::appkit::NSView` for the type `*mut objc::runtime::Object`
   = note: candidate #2 is defined in an impl of the trait `cocoa::appkit::NSTextField` for the type `*mut objc::runtime::Object`

Because NSView is implemented for id, are the other definitions of initWithFrame_ redundant? If so, can they be removed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.