Skip to content

Commit

Permalink
feat: Add OCaml Binding (#2757)
Browse files Browse the repository at this point in the history
* feat(binding/ocaml): init ocaml binding

* chore(binding/ocaml): license and ci

* chore: license

* chore: add readme

* chore: update ci

* update test file use ounit tempdir

* update ci

* update ci

* fix ci

* fix ci

* fix ci

* fix ci

* fix ci

* fix ci

* fix ci

* update ci try use dune cache

* update ci

* update ci

* update ci

* update ci

* update ci
  • Loading branch information
Ranxy committed Aug 4, 2023
1 parent dceea19 commit 0fcb442
Show file tree
Hide file tree
Showing 21 changed files with 663 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/actions/setup-ocaml/action.yaml
@@ -0,0 +1,41 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Setup OCaml
description: 'Prepare OCaml Build Environment'
inputs:
need-depext:
description: "Enable the automation feature for opam depext."
need-pin:
description: "Enable the automation feature for opam pin."

runs:
using: "composite"
steps:
- name: Setup OCaml
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: 4.14
opam-depext: ${{inputs.need-depext == true}}
opam-pin: ${{inputs.need-pin == true}}

- name: Set Opam env
shell: bash
run: opam env | tr '\n' ' ' >> $GITHUB_ENV
- name: Add Opam switch to PATH
shell: bash
run: opam var bin >> $GITHUB_PATH
58 changes: 58 additions & 0 deletions .github/workflows/bindings_ocaml.yml
@@ -0,0 +1,58 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Bindings OCaml CI

on:
push:
branches:
- main
tags:
- '*'
pull_request:
branches:
- main
paths:
- "bindings/ocaml/**"
- ".github/workflows/bindings_ocaml.yml"
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout PR
uses: actions/checkout@v2

- name: Setup OCaml toolchain
uses: ./.github/actions/setup-ocaml
with:
need-depext: true
need-pin: true

- name: Checks
run: |
# make sure tests pass
opam install -y dune ounit2 ocamlformat
eval $(opam env)
cd bindings/ocaml
dune runtest
dune build @fmt
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -75,6 +75,9 @@ jobs:
distribution: temurin
java-version: "11"

- name: Setup OCaml toolchain
uses: ./.github/actions/setup-ocaml

- name: Cargo doc
run: cargo doc --lib --no-deps --all-features -p opendal

Expand All @@ -99,6 +102,8 @@ jobs:
with:
distribution: temurin
java-version: "11"
- name: Setup OCaml toolchain
uses: ./.github/actions/setup-ocaml

- name: Cargo clippy
run: cargo clippy --all-targets --all-features --workspace -- -D warnings
Expand Down Expand Up @@ -145,6 +150,8 @@ jobs:
with:
distribution: temurin
java-version: "11"
- name: Setup OCaml toolchain
uses: ./.github/actions/setup-ocaml

- name: Setup Rust toolchain
uses: ./.github/actions/setup
Expand All @@ -168,6 +175,8 @@ jobs:
with:
distribution: temurin
java-version: "11"
- name: Setup OCaml toolchain
uses: ./.github/actions/setup-ocaml

- name: Setup Rust toolchain
uses: ./.github/actions/setup
Expand Down
87 changes: 87 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -33,6 +33,7 @@ members = [
"bindings/haskell",
"bindings/lua",
"bindings/dotnet",
"bindings/ocaml",

"bin/oli",
"bin/oay",
Expand Down
1 change: 1 addition & 0 deletions bindings/ocaml/.gitignore
@@ -0,0 +1 @@
_build
Empty file added bindings/ocaml/.ocamlformat
Empty file.
1 change: 1 addition & 0 deletions bindings/ocaml/.ocamlformat-ignore
@@ -0,0 +1 @@
src/**
40 changes: 40 additions & 0 deletions bindings/ocaml/Cargo.toml
@@ -0,0 +1,40 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

[package]
name = "opendal-ocaml"
publish = false

authors.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[lib]
crate-type = ["staticlib", "cdylib"]
doc = false

[dependencies]
opendal.workspace = true
ocaml = {version = "^1.0.0-beta"}

[build-dependencies]
ocaml-build = {version = "^1.0.0-beta"}

22 changes: 22 additions & 0 deletions bindings/ocaml/README.md
@@ -0,0 +1,22 @@
# OpenDAL OCaml Binding (WIP)

## Requirements

* OCaml version > 4.03 and < 5.0.0


## Build



```bash
cd bindings/ocaml
dune build
```

## Test

```bash
cd bindings/ocaml
dune test
```
20 changes: 20 additions & 0 deletions bindings/ocaml/build.rs
@@ -0,0 +1,20 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

pub fn main() -> std::io::Result<()> {
ocaml_build::Sigs::new("src/opendal.ml").generate()
}
18 changes: 18 additions & 0 deletions bindings/ocaml/dune
@@ -0,0 +1,18 @@
; Licensed to the Apache Software Foundation (ASF) under one
; or more contributor license agreements. See the NOTICE file
; distributed with this work for additional information
; regarding copyright ownership. The ASF licenses this file
; to you under the Apache License, Version 2.0 (the
; "License"); you may not use this file except in compliance
; with the License. You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing,
; software distributed under the License is distributed on an
; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
; KIND, either express or implied. See the License for the
; specific language governing permissions and limitations
; under the License.

(dirs :standard \ target)

0 comments on commit 0fcb442

Please sign in to comment.