Skip to content

Commit 3011af1

Browse files
committed
D bindings
* `std.paralellism` support added (write/read/list) * CI/CD test * rename `is_exists` - ref.: #5199 Signed-off-by: Matheus C. França <[email protected]>
1 parent df471e5 commit 3011af1

19 files changed

+858
-0
lines changed

.devcontainer/post_create.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,6 @@ opam install -y dune ounit2 ocamlformat
6969

7070
# Setup for Cpp binding
7171
sudo apt install -y ninja-build
72+
73+
# Setup for D binding
74+
sudo apt install -y dmd dub

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ integrations export-ignore
88

99
bindings/c export-ignore
1010
bindings/cpp export-ignore
11+
bindings/d export-ignore
1112
bindings/dotnet export-ignore
1213
bindings/go export-ignore
1314
bindings/haskell export-ignore

.github/workflows/ci_bindings_d.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: Bindings D CI
19+
20+
on:
21+
push:
22+
branches:
23+
- main
24+
tags:
25+
- "*"
26+
pull_request:
27+
branches:
28+
- main
29+
paths:
30+
- "core/**"
31+
- "bindings/c/**"
32+
- "bindings/d/**"
33+
- ".github/workflows/ci_bindings_d.yml"
34+
workflow_dispatch:
35+
36+
concurrency:
37+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
38+
cancel-in-progress: true
39+
40+
permissions:
41+
contents: read
42+
43+
jobs:
44+
test:
45+
strategy:
46+
matrix:
47+
# dmd: base (self-hosting) compiler (frontend & backend)
48+
# ldc2/ldmd2: (dmd-frontend + LLVM backend) - recommended for MacOS ARM64
49+
dlang: ["ldc-latest", "dmd-latest"]
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v4
53+
- uses: dlang-community/setup-dlang@v2
54+
with:
55+
compiler: ${{ matrix.dlang }}
56+
57+
- name: Setup Rust toolchain
58+
uses: ./.github/actions/setup
59+
60+
- name: Build D binding
61+
working-directory: bindings/d
62+
run: dub build
63+
64+
- name: Check diff
65+
run: git diff --exit-code
66+
67+
- name: Check
68+
working-directory: bindings/d
69+
run: dub lint
70+
71+
- name: Run tests
72+
working-directory: bindings/d
73+
run: dub test && cd test && dub

.typos.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ extend-exclude = [
3636
# Generated pnpm locks.
3737
"website/pnpm-lock.yaml",
3838
"CHANGELOG.md",
39+
# dscanner config
40+
"bindings/d/dscanner.ini",
3941
]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ OpenDAL offers a unified data access layer, empowering users to seamlessly and e
1414
| [Rust Core] | [![Rust Core Image]][Rust Core Link] | [![Docs Release]][Rust Core Release Docs] [![Docs Dev]][Rust Core Dev Docs] |
1515
| [C Binding] | - | [![Docs Dev]][C Binding Dev Docs] |
1616
| [Cpp Binding] | - | [![Docs Dev]][Cpp Binding Dev Docs] |
17+
| [D Binding] | - | - |
1718
| [Dotnet Binding] | - | - |
1819
| [Go Binding] | [![Go Binding Image]][Go Binding Link] | [![Docs Release]][Go Release Docs] |
1920
| [Haskell Binding] | - | - |
@@ -38,6 +39,7 @@ OpenDAL offers a unified data access layer, empowering users to seamlessly and e
3839
[C Binding Dev Docs]: https://opendal.apache.org/docs/c/
3940
[Cpp Binding]: bindings/cpp/README.md
4041
[Cpp Binding Dev Docs]: https://opendal.apache.org/docs/cpp/
42+
[D Binding]: bindings/d/README.md
4143
[Dotnet Binding]: bindings/dotnet/README.md
4244
[Go Binding]: bindings/go/README.md
4345
[Go Binding Image]: https://badge.fury.io/go/github.com%2Fapache%2Fopendal%2Fbindings%2Fgo.svg

bindings/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This folder contains the bindings for OpenDAL. Currently, we support the followi
1313
* [C](c/README.md)
1414
* [C++](cpp/README.md)
1515
* [C#](dotnet/README.md)
16+
* [D](d/README.md)
1617
* [Go](go/README.md)
1718
* [Haskell](haskell/README.md)
1819
* [Lua](lua/README.md)

bindings/d/.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.dub
2+
docs.json
3+
__dummy.html
4+
docs/
5+
/d
6+
d.so
7+
d.dylib
8+
d.dll
9+
d.a
10+
d.lib
11+
d-test-*
12+
*.exe
13+
*.pdb
14+
*.o
15+
*.obj
16+
*.lst
17+
*.h
18+
*.a
19+
*.ninja_log
20+
tests*

bindings/d/CONTRIBUTING.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Contributing
2+
3+
- [Contributing](#contributing)
4+
- [Setup](#setup)
5+
- [Using a dev container environment](#using-a-dev-container-environment)
6+
- [Bring your own toolbox](#bring-your-own-toolbox)
7+
- [Build](#build)
8+
- [Test](#test)
9+
10+
## Setup
11+
12+
### Using a dev container environment
13+
14+
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.
15+
16+
The fastest way is:
17+
18+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/apache/opendal?quickstart=1&machine=standardLinux32gb)
19+
20+
### Bring your own toolbox
21+
22+
To build OpenDAL D binding locally, you need:
23+
24+
- [dmd/ldc/gdc](https://dlang.org/download)
25+
26+
27+
## Build
28+
29+
First, build the C bindings:
30+
31+
```shell
32+
dub build -b release
33+
```
34+
35+
> **Note**:
36+
>
37+
> - `dub build` adds the header file `opendal.h` under `../c/include`
38+
> - The library is under `../../target/debug` or `../../target/release` after building.
39+
40+
## Test
41+
42+
To build and run the tests.
43+
44+
```shell
45+
$ dub test
46+
Generating test runner configuration 'opendal-test-unittest' for 'unittest' (library).
47+
Starting Performing "unittest" build using /usr/bin/ldc2 for x86_64.
48+
Building opendal ~master: building configuration [opendal-test-unittest]
49+
Pre-build Running commands
50+
Finished `release` profile [optimized] target(s) in 0.08s
51+
Cargo build completed successfully
52+
Linking opendal-test-unittest
53+
Running opendal-test-unittest
54+
Basic Operator creation and write test passed
55+
1 modules passed unittests
56+
```
57+
58+

bindings/d/DEPENDENCIES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Dependencies
2+
3+
OpenDAL D Binding is based on the C Binding.
4+
There are no extra runtime dependencies except those conveyed from C Binding.

bindings/d/DEPENDENCIES.rust.tsv

Whitespace-only changes.

bindings/d/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Apache OpenDAL™ D Binding (WIP)
2+
3+
![](https://img.shields.io/badge/status-unreleased-red)
4+
5+
![](https://github.com/apache/opendal/assets/5351546/87bbf6e5-f19e-449a-b368-3e283016c887)
6+
7+
## Build
8+
9+
To compile OpenDAL from source code, you need:
10+
11+
- [dmd/ldc/gdc](https://dlang.org/download)
12+
13+
```bash
14+
# build libopendal_c (underneath call make -C ../c)
15+
dub build -b release
16+
# build and run unit tests
17+
dub test
18+
```
19+
20+
## License and Trademarks
21+
22+
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
23+
24+
Apache OpenDAL, OpenDAL, and Apache are either registered trademarks or trademarks of the Apache Software Foundation.

bindings/d/build.d

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module build;
2+
import std.stdio: writeln;
3+
import std.path: buildPath;
4+
import std.process: spawnShell, wait;
5+
import std.exception;
6+
import std.file: copy, mkdir, exists;
7+
import std.conv: to;
8+
9+
version (Windows)
10+
enum staticlib = "opendal_c.lib";
11+
else
12+
enum staticlib = "libopendal_c.a";
13+
14+
void main (string[] args)
15+
{
16+
bool isRelease = args.length > 1 && args[1] == "release";
17+
string buildType = isRelease ? "release" : "debug";
18+
19+
// Run cargo build
20+
auto cargoCmd = "cargo build --manifest-path " ~ buildPath(
21+
"..", "c", "Cargo.toml") ~ (isRelease ? " --release" : "");
22+
23+
auto status = wait(spawnShell(cargoCmd));
24+
if (status != 0)
25+
{
26+
throw new Exception("Cargo build failed with status: " ~ status.to!string);
27+
}
28+
else
29+
{
30+
writeln("Cargo build completed successfully");
31+
}
32+
33+
// Get opendal.h
34+
copy(buildPath("..", "c", "include", "opendal.h"), buildPath("source", "opendal", "opendal.h"));
35+
36+
// Get libopendal_c.a
37+
auto libPath = buildPath("..", "c", "target", buildType, staticlib);
38+
writeln("Copying ", libPath, " to ", buildPath("lib", staticlib));
39+
if (!exists("lib"))
40+
mkdir ("lib");
41+
copy(libPath, buildPath("lib", staticlib));
42+
}

bindings/d/dscanner.ini

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
; Configure which static analysis checks are enabled
2+
[analysis.config.StaticAnalysisConfig]
3+
; Check variable, class, struct, interface, union, and function names against
4+
; the Phobos style guide
5+
style_check="disabled"
6+
; Check for array literals that cause unnecessary allocation
7+
enum_array_literal_check="enabled"
8+
; Check for poor exception handling practices
9+
exception_check="enabled"
10+
; Check for use of the deprecated 'delete' keyword
11+
delete_check="enabled"
12+
; Check for use of the deprecated floating point operators
13+
float_operator_check="enabled"
14+
; Check underscores to improve number constant readability
15+
number_style_check="enabled"
16+
; Checks that opEquals, opCmp, toHash, and toString are either const, immutable
17+
; , or inout.
18+
object_const_check="enabled"
19+
; Checks for .. expressions where the left side is larger than the right.
20+
backwards_range_check="enabled"
21+
; Checks for if statements whose 'then' block is the same as the 'else' block
22+
if_else_same_check="enabled"
23+
; Checks for some problems with constructors
24+
constructor_check="enabled"
25+
; Checks for unused function parameters
26+
unused_parameter_check="disabled"
27+
; Checks for unused variables
28+
unused_variable_check="enabled"
29+
; Checks for unused labels
30+
unused_label_check="enabled"
31+
; Checks for duplicate attributes
32+
duplicate_attribute="enabled"
33+
; Checks that opEquals and toHash are both defined or neither are defined
34+
opequals_tohash_check="disabled"
35+
; Checks for subtraction from .length properties
36+
length_subtraction_check="disabled"
37+
; Checks for methods or properties whose names conflict with built-in propertie
38+
; s
39+
builtin_property_names_check="enabled"
40+
; Checks for confusing code in inline asm statements
41+
asm_style_check="enabled"
42+
; Checks for confusing logical operator precedence
43+
logical_precedence_check="disabled"
44+
; Checks for undocumented public declarations
45+
undocumented_declaration_check="disabled"
46+
; Checks for poor placement of function attributes
47+
function_attribute_check="enabled"
48+
; Checks for use of the comma operator
49+
comma_expression_check="enabled"
50+
; Checks for local imports that are too broad
51+
local_import_check="disabled"
52+
; Checks for variables that could be declared immutable
53+
could_be_immutable_check="disabled"
54+
; Checks for redundant expressions in if statements
55+
redundant_if_check="enabled"
56+
; Checks for redundant parenthesis
57+
redundant_parens_check="disabled"
58+
; Checks for mismatched argument and parameter names
59+
mismatched_args_check="disabled"
60+
; Checks for labels with the same name as variables
61+
label_var_same_name_check="disabled"
62+
; Checks for lines longer than 120 characters
63+
long_line_check="disabled"
64+
; Checks for assignment to auto-ref function parameters
65+
auto_ref_assignment_check="disabled"
66+
; Checks for incorrect infinite range definitions
67+
incorrect_infinite_range_check="enabled"
68+
; Checks for asserts that are always true
69+
useless_assert_check="enabled"
70+
; Check for uses of the old-style alias syntax
71+
alias_syntax_check="enabled"
72+
; Checks for else if that should be else static if
73+
static_if_else_check="enabled"
74+
; Check for unclear lambda syntax
75+
lambda_return_check="enabled"
76+
; Check for auto function without return statement
77+
auto_function_check="enabled"
78+
; Check for sortedness of imports
79+
imports_sortedness="disabled"
80+
; Check for explicitly annotated unittests
81+
explicitly_annotated_unittests="disabled"
82+
; Check for properly documented public functions (Returns, Params)
83+
properly_documented_public_functions="disabled"
84+
; Check for useless usage of the final attribute
85+
final_attribute_check="enabled"
86+
; Check for virtual calls in the class constructors
87+
vcall_in_ctor="enabled"
88+
; Check for useless user defined initializers
89+
useless_initializer="disabled"
90+
; Check allman brace style
91+
allman_braces_check="disabled"
92+
; Check for redundant attributes
93+
redundant_attributes_check="disabled"
94+
; Check for public declarations without a documented unittest
95+
has_public_example="disabled"
96+
; Check for asserts without an explanatory message
97+
assert_without_msg="disabled"
98+
; Check indent of if constraints
99+
if_constraints_indent="enabled"
100+
; Check for @trusted applied to a bigger scope than a single function
101+
trust_too_much="disabled"
102+
; Check for redundant storage classes on variable declarations")
103+
redundant_storage_classes="enabled"
104+
; Check for unused function return values
105+
unused_result="disabled"

0 commit comments

Comments
 (0)