Skip to content
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

feat: Add OCaml Binding #2757

Merged
merged 21 commits into from
Aug 4, 2023
Merged
42 changes: 42 additions & 0 deletions .github/actions/setup-ocaml/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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
dune-cache: true
opam-depext: ${{inputs.need-depext}}
opam-pin: ${{inputs.need-pin}}

- 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
Original file line number Diff line number Diff line change
@@ -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



21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ jobs:
distribution: temurin
java-version: "11"

- name: Setup OCaml toolchain
uses: ./.github/actions/setup-ocaml
with:
need-depext: false
Ranxy marked this conversation as resolved.
Show resolved Hide resolved
need-pin: false

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

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

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

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

- 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_build
Empty file added bindings/ocaml/.ocamlformat
Empty file.
1 change: 1 addition & 0 deletions bindings/ocaml/.ocamlformat-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/**
40 changes: 40 additions & 0 deletions bindings/ocaml/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)