Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
dboris committed May 19, 2024
1 parent 79b65e8 commit 32e1594
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 116 deletions.
32 changes: 11 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Camlkit provides OCaml bindings to the following Cocoa frameworks:
* [Photos](https://developer.apple.com/documentation/photos?language=objc)
(iOS and macOS)


## Features

* Using the classes and objects from these Cocoa frameworks, defining new
Expand All @@ -28,6 +29,7 @@ Camlkit provides OCaml bindings to the following Cocoa frameworks:
* An Xcode project is not required. A complete macOS or iOS application can
be developed entirely in OCaml.


## Sample programs

A few sample programs are provided in the
Expand All @@ -38,7 +40,7 @@ application:
```ocaml
open Foundation
open Uikit
open Uikit_
open Uikit_globals
open Runtime
module AppDelegate = struct
Expand Down Expand Up @@ -96,6 +98,7 @@ as a starting template. Read the Apple documentation for the classes and methods
of interest. All books on iOS and macOS development in Objective-C are directly
applicable. Below is a short introduction to Camlkit.


## Introduction

If you are familiar with Cocoa development in Objective-C or Swift, transferring
Expand Down Expand Up @@ -181,26 +184,6 @@ constructs by comparing the equivalent Objective-C and OCaml code.
an_instance |> msg_send (selector "anArbitrarySelector") ~args: Objc_t.[] ~return: Objc_t.void
```

## Setup

For macOS development, pin and install the following packages:

```sh
opam pin add -y camlkit-base https://github.com/dboris/camlkit.git
opam pin add -y camlkit-gui https://github.com/dboris/camlkit.git
opam pin add -y camlkit https://github.com/dboris/camlkit.git
```

For iOS and Mac Catalyst development you will need to set up a cross-toolchain
from [opam-cross-ios](https://github.com/ocaml-cross/opam-cross-ios).
Then install the following packages:

```sh
opam pin add -y camlkit-base-ios https://github.com/dboris/camlkit.git
opam pin add -y camlkit-gui-ios https://github.com/dboris/camlkit.git
opam pin add -y camlkit-ios https://github.com/dboris/camlkit.git
```

## Documentation

At this time, the documentation of the project is lacking. The framework
Expand All @@ -213,8 +196,15 @@ Some usefull sources you may wish to examine include:
* [Usage examples](https://github.com/dboris/camlkit-examples/)
* [The Ctypes documentation](https://ocaml.org/p/ctypes/latest/doc/Ctypes/index.html)


## Project status

The project is in active development but is still experimental. It can be
considered at the alpha stage. If you are an early adopter, keep in mind
that the API is subject to change.


## Related projects

For iOS and Mac Catalyst development you will need to set up a cross-toolchain
from [opam-cross-ios](https://github.com/ocaml-cross/opam-cross-ios).
File renamed without changes.
2 changes: 1 addition & 1 deletion appkit/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
(name appkit)
(public_name camlkit-gui.appkit)
(flags :standard -ccopt "-framework AppKit")
(libraries foundation))
(libraries camlkit-base.foundation))
7 changes: 4 additions & 3 deletions bin/main.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
open Foundation
open Runtime
open Appkit
open Appkit_globals
(* open Webkit *)

let win_width = 400.
Expand All @@ -11,12 +12,12 @@ let app_window () =
alloc NSWindow._class_
|> NSWindow.initWithContentRect
(CGRect.make ~x: 0. ~y: 0. ~width: win_width ~height: win_height)
~styleMask: (combine_options Appkit_.[
~styleMask: (combine_options [
_NSWindowStyleMaskTitled;
_NSWindowStyleMaskClosable;
_NSWindowStyleMaskResizable
])
~backing: Appkit_._NSBackingStoreBuffered
~backing: _NSBackingStoreBuffered
~defer: false
in
win
Expand Down Expand Up @@ -70,7 +71,7 @@ let main () =
win |> NSWindow.contentView |> NSView.addSubview btn;
(* win |> content_view |> add_subview wv; *)
assert (app |> NSApplication.setActivationPolicy
Appkit_._NSApplicationActivationPolicyRegular);
_NSApplicationActivationPolicyRegular);
app |> NSApplication.activateIgnoringOtherApps true;
NSApplication.run app

Expand Down
10 changes: 5 additions & 5 deletions camlkit-base.opam
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.1.1"
synopsis:
"OCaml bindings to the Objective-C runtime and some base frameworks"
description: """\
description: """

This package provides OCaml bindings to the Objective-C runtime and
the following macOS frameworks: Foundation, WebKit, Vision, CoreImage, and Photos.
"""
the following Cocoa frameworks: Foundation, WebKit, Vision, CoreImage, and Photos."""
maintainer: ["Boris D. <[email protected]>"]
authors: ["Boris D. <[email protected]>"]
license: "ISC"
tags: ["objc" "bindings" "cocoa" "gnustep"]
tags: ["objc" "bindings" "cocoa" "macos" "gnustep"]
homepage: "https://github.com/dboris/camlkit"
bug-reports: "https://github.com/dboris/camlkit/issues"
depends: [
"ocaml"
"dune" {>= "3.13"}
"ctypes"
"ctypes-foreign"
Expand Down
5 changes: 2 additions & 3 deletions camlkit-gui.opam
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.1.1"
synopsis: "OCaml bindings to the AppKit framework"
description: "OCaml bindings to the AppKit framework"
maintainer: ["Boris D. <[email protected]>"]
authors: ["Boris D. <[email protected]>"]
license: "ISC"
tags: ["objc" "bindings" "cocoa" "gnustep"]
tags: ["objc" "bindings" "cocoa" "macos" "gnustep"]
homepage: "https://github.com/dboris/camlkit"
bug-reports: "https://github.com/dboris/camlkit/issues"
depends: [
"ocaml"
"dune" {>= "3.13"}
"camlkit-base" {= version}
"alcotest" {with-test}
"odoc" {with-doc}
]
build: [
Expand Down
5 changes: 2 additions & 3 deletions camlkit.opam
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.1.1"
synopsis: "Higher-level wrappers for Cocoa APIs"
description: "Higher-level wrappers for Cocoa APIs"
maintainer: ["Boris D. <[email protected]>"]
authors: ["Boris D. <[email protected]>"]
license: "ISC"
tags: ["objc" "cocoa" "ios" "gnustep"]
tags: ["objc" "cocoa" "macos" "gnustep"]
homepage: "https://github.com/dboris/camlkit"
bug-reports: "https://github.com/dboris/camlkit/issues"
depends: [
"ocaml"
"dune" {>= "3.13"}
"camlkit-base" {= version}
"camlkit-gui" {= version}
"alcotest" {with-test}
"odoc" {with-doc}
]
build: [
Expand Down
2 changes: 1 addition & 1 deletion camlkit/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(library
(name camlkit)
(public_name camlkit)
(public_name camlkit.camlkit)
(libraries foundation))
2 changes: 1 addition & 1 deletion demo/main.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Foundation
open Uikit
open Uikit_
open Uikit_globals
open Runtime

module AppDelegate = struct
Expand Down
63 changes: 9 additions & 54 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(lang dune 3.13)
(using ctypes 0.3)
; (using ctypes 0.3)

(name camlkit)
(version 0.1.1)

(generate_opam_files false)
(generate_opam_files true)

(source (github dboris/camlkit))

Expand All @@ -15,72 +15,27 @@
(package
(name camlkit-base)
(synopsis "OCaml bindings to the Objective-C runtime and some base frameworks")
(description "OCaml bindings to the Objective-C runtime and some base frameworks")
(description "
This package provides OCaml bindings to the Objective-C runtime and
the following Cocoa frameworks: Foundation, WebKit, Vision, CoreImage, and Photos.")
(depends
ocaml
dune
ctypes
ctypes-foreign
(alcotest :with-test))
(tags (objc bindings cocoa gnustep)))
(tags (objc bindings cocoa macos gnustep)))

(package
(name camlkit-gui)
(synopsis "OCaml bindings to the AppKit framework")
(description "OCaml bindings to the AppKit framework")
(depends
ocaml
dune
(camlkit-base (= :version))
(alcotest :with-test))
(depends (camlkit-base (= :version)))
(tags (objc bindings cocoa macos gnustep)))

(package
(name camlkit)
(synopsis "Higher-level wrappers for Cocoa APIs")
(description "Higher-level wrappers for Cocoa APIs")
(depends
ocaml
dune
(camlkit-base (= :version))
(camlkit-gui (= :version))
(alcotest :with-test))
(tags (objc cocoa ios gnustep)))

(package
(name camlkit-base-ios)
(synopsis "OCaml bindings to the Objective-C runtime and some base frameworks")
(description "OCaml bindings to the Objective-C runtime and some base frameworks")
(allow_empty)
(depends
ocaml
dune
ctypes
ctypes-foreign
(alcotest :with-test))
(tags (objc bindings cocoa ios)))

(package
(name camlkit-gui-ios)
(synopsis "OCaml bindings to the UIKit framework")
(description "OCaml bindings to the UIKit framework")
(allow_empty)
(depends
ocaml
dune
(camlkit-base (= :version))
(alcotest :with-test))
(tags (objc bindings cocoa ios)))

(package
(name camlkit-ios)
(synopsis "Higher-level wrappers for Cocoa APIs")
(description "Higher-level wrappers for Cocoa APIs")
(allow_empty)
(depends
ocaml
dune
(camlkit-base-ios (= :version))
(camlkit-gui-ios (= :version))
(alcotest :with-test))
(tags (objc cocoa ios)))
(camlkit-gui (= :version)))
(tags (objc cocoa macos gnustep)))
3 changes: 1 addition & 2 deletions foundation/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(name foundation)
(public_name camlkit-base.foundation)
(flags :standard -ccopt "-framework Foundation")
(library_flags :standard -linkall)
(libraries runtime ctypes))
(libraries camlkit-base.runtime))

(documentation (package camlkit-base))
File renamed without changes.
25 changes: 17 additions & 8 deletions camlkit-base-ios.opam → ios-pkgs/camlkit-base-ios.opam
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.1.1"
synopsis:
"OCaml bindings to the Objective-C runtime and some base frameworks"
description: """\
description: """

This package provides OCaml bindings to the Objective-C runtime and
the following iOS frameworks: Foundation, WebKit, Vision, CoreImage, and Photos.
"""
the following iOS frameworks: Foundation, WebKit, Vision, CoreImage, and Photos."""
maintainer: ["Boris D. <[email protected]>"]
authors: ["Boris D. <[email protected]>"]
license: "ISC"
tags: ["objc" "bindings" "cocoa" "ios"]
homepage: "https://github.com/dboris/camlkit"
bug-reports: "https://github.com/dboris/camlkit/issues"
depends: [
"ocaml-ios"
"dune" {>= "3.13"}
"ocaml-ios"
"ctypes-ios"
"ctypes-foreign-ios"
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune" "build"
"-p" "camlkit-base"
"-j" jobs
"-x" "ios"
"dune"
"build"
"-p"
"camlkit-base"
"-j"
jobs
"-x"
"ios"
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/dboris/camlkit.git"
19 changes: 14 additions & 5 deletions camlkit-gui-ios.opam → ios-pkgs/camlkit-gui-ios.opam
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.1.1"
synopsis: "OCaml bindings to the UIKit framework"
Expand All @@ -9,17 +10,25 @@ tags: ["objc" "bindings" "cocoa" "ios"]
homepage: "https://github.com/dboris/camlkit"
bug-reports: "https://github.com/dboris/camlkit/issues"
depends: [
"ocaml-ios"
"dune" {>= "3.13"}
"ocaml-ios"
"camlkit-base-ios" {= version}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune" "build"
"-p" "camlkit-gui"
"-j" jobs
"-x" "ios"
"dune"
"build"
"-p"
"camlkit-gui"
"-j"
jobs
"-x"
"ios"
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/dboris/camlkit.git"
Loading

0 comments on commit 32e1594

Please sign in to comment.