Skip to content

Commit

Permalink
D bindings
Browse files Browse the repository at this point in the history
* `std.paralellism` support added (write/read/list)
* CI/CD test
* rename `is_exists` - ref.: #5199

Signed-off-by: Matheus C. França  <[email protected]>
  • Loading branch information
kassane committed Oct 21, 2024
1 parent a124579 commit 7ddea57
Show file tree
Hide file tree
Showing 19 changed files with 858 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .devcontainer/post_create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ opam install -y dune ounit2 ocamlformat

# Setup for Cpp binding
sudo apt install -y ninja-build

# Setup for D binding
sudo apt install -y dmd dub
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ integrations export-ignore

bindings/c export-ignore
bindings/cpp export-ignore
bindings/d export-ignore
bindings/dotnet export-ignore
bindings/go export-ignore
bindings/haskell export-ignore
Expand Down
73 changes: 73 additions & 0 deletions .github/workflows/ci_bindings_d.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# 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 D CI

on:
push:
branches:
- main
tags:
- "*"
pull_request:
branches:
- main
paths:
- "core/**"
- "bindings/c/**"
- "bindings/d/**"
- ".github/workflows/ci_bindings_d.yml"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

permissions:
contents: read

jobs:
test:
strategy:
matrix:
# dmd: base (self-hosting) compiler (frontend & backend)
# ldc2/ldmd2: (dmd-frontend + LLVM backend) - recommended for MacOS ARM64
dlang: ["ldc-latest", "dmd-latest"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dlang-community/setup-dlang@v2
with:
compiler: ${{ matrix.dlang }}

- name: Setup Rust toolchain
uses: ./.github/actions/setup

- name: Build D binding
working-directory: bindings/d
run: dub build

- name: Check diff
run: git diff --exit-code

- name: Check
working-directory: bindings/d
run: dub lint

- name: Run tests
working-directory: bindings/d
run: dub test && cd test && dub
2 changes: 2 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ extend-exclude = [
# Generated pnpm locks.
"website/pnpm-lock.yaml",
"CHANGELOG.md",
# dscanner config
"bindings/d/dscanner.ini",
]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ OpenDAL offers a unified data access layer, empowering users to seamlessly and e
| [Rust Core] | [![Rust Core Image]][Rust Core Link] | [![Docs Release]][Rust Core Release Docs] [![Docs Dev]][Rust Core Dev Docs] |
| [C Binding] | - | [![Docs Dev]][C Binding Dev Docs] |
| [Cpp Binding] | - | [![Docs Dev]][Cpp Binding Dev Docs] |
| [D Binding] | - | - |
| [Dotnet Binding] | - | - |
| [Go Binding] | [![Go Binding Image]][Go Binding Link] | [![Docs Release]][Go Release Docs] |
| [Haskell Binding] | - | - |
Expand All @@ -38,6 +39,7 @@ OpenDAL offers a unified data access layer, empowering users to seamlessly and e
[C Binding Dev Docs]: https://opendal.apache.org/docs/c/
[Cpp Binding]: bindings/cpp/README.md
[Cpp Binding Dev Docs]: https://opendal.apache.org/docs/cpp/
[D Binding]: bindings/d/README.md
[Dotnet Binding]: bindings/dotnet/README.md
[Go Binding]: bindings/go/README.md
[Go Binding Image]: https://badge.fury.io/go/github.com%2Fapache%2Fopendal%2Fbindings%2Fgo.svg
Expand Down
1 change: 1 addition & 0 deletions bindings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This folder contains the bindings for OpenDAL. Currently, we support the followi
* [C](c/README.md)
* [C++](cpp/README.md)
* [C#](dotnet/README.md)
* [D](d/README.md)
* [Go](go/README.md)
* [Haskell](haskell/README.md)
* [Lua](lua/README.md)
Expand Down
20 changes: 20 additions & 0 deletions bindings/d/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.dub
docs.json
__dummy.html
docs/
/d
d.so
d.dylib
d.dll
d.a
d.lib
d-test-*
*.exe
*.pdb
*.o
*.obj
*.lst
*.h
*.a
*.ninja_log
tests*
58 changes: 58 additions & 0 deletions bindings/d/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Contributing

- [Contributing](#contributing)
- [Setup](#setup)
- [Using a dev container environment](#using-a-dev-container-environment)
- [Bring your own toolbox](#bring-your-own-toolbox)
- [Build](#build)
- [Test](#test)

## Setup

### Using a dev container environment

OpenDAL provides a pre-configured [dev container](https://containers.dev/) that could be used in [GitHub Codespaces](https://github.com/features/codespaces), [VSCode](https://code.visualstudio.com/), [JetBrains](https://www.jetbrains.com/remote-development/gateway/), [JupyterLab](https://jupyterlab.readthedocs.io/en/stable/). Please pick up your favourite runtime environment.

The fastest way is:

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/apache/opendal?quickstart=1&machine=standardLinux32gb)

### Bring your own toolbox

To build OpenDAL D binding locally, you need:

- [dmd/ldc/gdc](https://dlang.org/download)


## Build

First, build the C bindings:

```shell
dub build -b release
```

> **Note**:
>
> - `dub build` adds the header file `opendal.h` under `../c/include`
> - The library is under `../../target/debug` or `../../target/release` after building.
## Test

To build and run the tests.

```shell
$ dub test
Generating test runner configuration 'opendal-test-unittest' for 'unittest' (library).
Starting Performing "unittest" build using /usr/bin/ldc2 for x86_64.
Building opendal ~master: building configuration [opendal-test-unittest]
Pre-build Running commands
Finished `release` profile [optimized] target(s) in 0.08s
Cargo build completed successfully
Linking opendal-test-unittest
Running opendal-test-unittest
Basic Operator creation and write test passed
1 modules passed unittests
```


4 changes: 4 additions & 0 deletions bindings/d/DEPENDENCIES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Dependencies

OpenDAL D Binding is based on the C Binding.
There are no extra runtime dependencies except those conveyed from C Binding.
Empty file.
24 changes: 24 additions & 0 deletions bindings/d/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Apache OpenDAL™ D Binding (WIP)

![](https://img.shields.io/badge/status-unreleased-red)

![](https://github.com/apache/opendal/assets/5351546/87bbf6e5-f19e-449a-b368-3e283016c887)

## Build

To compile OpenDAL from source code, you need:

- [dmd/ldc/gdc](https://dlang.org/download)

```bash
# build libopendal_c (underneath call make -C ../c)
dub build -b release
# build and run unit tests
dub test
```

## License and Trademarks

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

Apache OpenDAL, OpenDAL, and Apache are either registered trademarks or trademarks of the Apache Software Foundation.
42 changes: 42 additions & 0 deletions bindings/d/build.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module build;
import std.stdio: writeln;
import std.path: buildPath;
import std.process: spawnShell, wait;
import std.exception;
import std.file: copy, mkdir, exists;
import std.conv: to;

version (Windows)
enum staticlib = "opendal_c.lib";
else
enum staticlib = "libopendal_c.a";

void main (string[] args)
{
bool isRelease = args.length > 1 && args[1] == "release";
string buildType = isRelease ? "release" : "debug";

// Run cargo build
auto cargoCmd = "cargo build --manifest-path " ~ buildPath(
"..", "c", "Cargo.toml") ~ (isRelease ? " --release" : "");

auto status = wait(spawnShell(cargoCmd));
if (status != 0)
{
throw new Exception("Cargo build failed with status: " ~ status.to!string);
}
else
{
writeln("Cargo build completed successfully");
}

// Get opendal.h
copy(buildPath("..", "c", "include", "opendal.h"), buildPath("source", "opendal", "opendal.h"));

// Get libopendal_c.a
auto libPath = buildPath("..", "c", "target", buildType, staticlib);
writeln("Copying ", libPath, " to ", buildPath("lib", staticlib));
if (!exists("lib"))
mkdir ("lib");
copy(libPath, buildPath("lib", staticlib));
}
105 changes: 105 additions & 0 deletions bindings/d/dscanner.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
; Configure which static analysis checks are enabled
[analysis.config.StaticAnalysisConfig]
; Check variable, class, struct, interface, union, and function names against
; the Phobos style guide
style_check="disabled"
; Check for array literals that cause unnecessary allocation
enum_array_literal_check="enabled"
; Check for poor exception handling practices
exception_check="enabled"
; Check for use of the deprecated 'delete' keyword
delete_check="enabled"
; Check for use of the deprecated floating point operators
float_operator_check="enabled"
; Check underscores to improve number constant readability
number_style_check="enabled"
; Checks that opEquals, opCmp, toHash, and toString are either const, immutable
; , or inout.
object_const_check="enabled"
; Checks for .. expressions where the left side is larger than the right.
backwards_range_check="enabled"
; Checks for if statements whose 'then' block is the same as the 'else' block
if_else_same_check="enabled"
; Checks for some problems with constructors
constructor_check="enabled"
; Checks for unused function parameters
unused_parameter_check="disabled"
; Checks for unused variables
unused_variable_check="enabled"
; Checks for unused labels
unused_label_check="enabled"
; Checks for duplicate attributes
duplicate_attribute="enabled"
; Checks that opEquals and toHash are both defined or neither are defined
opequals_tohash_check="disabled"
; Checks for subtraction from .length properties
length_subtraction_check="disabled"
; Checks for methods or properties whose names conflict with built-in propertie
; s
builtin_property_names_check="enabled"
; Checks for confusing code in inline asm statements
asm_style_check="enabled"
; Checks for confusing logical operator precedence
logical_precedence_check="disabled"
; Checks for undocumented public declarations
undocumented_declaration_check="disabled"
; Checks for poor placement of function attributes
function_attribute_check="enabled"
; Checks for use of the comma operator
comma_expression_check="enabled"
; Checks for local imports that are too broad
local_import_check="disabled"
; Checks for variables that could be declared immutable
could_be_immutable_check="disabled"
; Checks for redundant expressions in if statements
redundant_if_check="enabled"
; Checks for redundant parenthesis
redundant_parens_check="disabled"
; Checks for mismatched argument and parameter names
mismatched_args_check="disabled"
; Checks for labels with the same name as variables
label_var_same_name_check="disabled"
; Checks for lines longer than 120 characters
long_line_check="disabled"
; Checks for assignment to auto-ref function parameters
auto_ref_assignment_check="disabled"
; Checks for incorrect infinite range definitions
incorrect_infinite_range_check="enabled"
; Checks for asserts that are always true
useless_assert_check="enabled"
; Check for uses of the old-style alias syntax
alias_syntax_check="enabled"
; Checks for else if that should be else static if
static_if_else_check="enabled"
; Check for unclear lambda syntax
lambda_return_check="enabled"
; Check for auto function without return statement
auto_function_check="enabled"
; Check for sortedness of imports
imports_sortedness="disabled"
; Check for explicitly annotated unittests
explicitly_annotated_unittests="disabled"
; Check for properly documented public functions (Returns, Params)
properly_documented_public_functions="disabled"
; Check for useless usage of the final attribute
final_attribute_check="enabled"
; Check for virtual calls in the class constructors
vcall_in_ctor="enabled"
; Check for useless user defined initializers
useless_initializer="disabled"
; Check allman brace style
allman_braces_check="disabled"
; Check for redundant attributes
redundant_attributes_check="disabled"
; Check for public declarations without a documented unittest
has_public_example="disabled"
; Check for asserts without an explanatory message
assert_without_msg="disabled"
; Check indent of if constraints
if_constraints_indent="enabled"
; Check for @trusted applied to a bigger scope than a single function
trust_too_much="disabled"
; Check for redundant storage classes on variable declarations")
redundant_storage_classes="enabled"
; Check for unused function return values
unused_result="disabled"
Loading

0 comments on commit 7ddea57

Please sign in to comment.