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

chore(bindings/C): ignore the formatting of auto-generated opendal.h #2056

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ all: build test

.PHONY: format
format:
find . \( -name '*.c' -o -name '*.h' \) -exec clang-format -i --style=WebKit --verbose {} \;
find . -name '*.c' -exec clang-format -i --style=WebKit --verbose {} \;

.PHONY: build
build:
Expand Down
2 changes: 1 addition & 1 deletion bindings/c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

To compile OpenDAL from source code, you'll need:
- C/C++ Toolchain: provides basic tools for compiling and linking OpenDAL C binding. This is available as `build-essential` on Ubuntu and similar names on other platforms.
- `clang-format`: OpenDAL uses clang-format to keep C binding code base clean.
- `clang-format`: OpenDAL uses clang-format to keep C binding code base clean. The `opendal.h` should be included and formatted by users manually.

```bash
make
Expand Down
16 changes: 0 additions & 16 deletions bindings/c/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,12 @@

extern crate cbindgen;

use std::io::ErrorKind;
use std::path::Path;
use std::process::Command;

fn main() {
let header_file = Path::new("include").join("opendal.h");

cbindgen::generate(".")
.expect("Unable to generate bindings")
.write_to_file(header_file);

if let Err(e) = Command::new("clang-format")
.arg("--style=WebKit")
.arg("--verbose")
.arg("-i")
.arg("include/opendal.h")
.spawn()
{
if e.kind() == ErrorKind::NotFound {
panic!("\x1b[31mclang-format\x1b[0m not found, please install it through package manager first");
} else {
panic!("Failed to run build.rs: {}", e)
}
}
}
127 changes: 64 additions & 63 deletions bindings/c/include/opendal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,65 +17,66 @@
* under the License.
*/


#ifndef _OPENDAL_H
#define _OPENDAL_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

/*
The error code for opendal APIs in C binding
*/
typedef enum opendal_code {
/*
All is well
*/
OPENDAL_OK,
/*
General error
*/
OPENDAL_ERROR,
/*
returning it back. For example, s3 returns an internal service error.
*/
OPENDAL_UNEXPECTED,
/*
Underlying service doesn't support this operation.
*/
OPENDAL_UNSUPPORTED,
/*
The config for backend is invalid.
*/
OPENDAL_CONFIG_INVALID,
/*
The given path is not found.
*/
OPENDAL_NOT_FOUND,
/*
The given path doesn't have enough permission for this operation
*/
OPENDAL_PERMISSION_DENIED,
/*
The given path is a directory.
*/
OPENDAL_IS_A_DIRECTORY,
/*
The given path is not a directory.
*/
OPENDAL_NOT_A_DIRECTORY,
/*
The given path already exists thus we failed to the specified operation on it.
*/
OPENDAL_ALREADY_EXISTS,
/*
Requests that sent to this path is over the limit, please slow down.
*/
OPENDAL_RATE_LIMITED,
/*
The given file paths are same.
*/
OPENDAL_IS_SAME_FILE,
/*
All is well
*/
OPENDAL_OK,
/*
General error
*/
OPENDAL_ERROR,
/*
returning it back. For example, s3 returns an internal service error.
*/
OPENDAL_UNEXPECTED,
/*
Underlying service doesn't support this operation.
*/
OPENDAL_UNSUPPORTED,
/*
The config for backend is invalid.
*/
OPENDAL_CONFIG_INVALID,
/*
The given path is not found.
*/
OPENDAL_NOT_FOUND,
/*
The given path doesn't have enough permission for this operation
*/
OPENDAL_PERMISSION_DENIED,
/*
The given path is a directory.
*/
OPENDAL_IS_A_DIRECTORY,
/*
The given path is not a directory.
*/
OPENDAL_NOT_A_DIRECTORY,
/*
The given path already exists thus we failed to the specified operation on it.
*/
OPENDAL_ALREADY_EXISTS,
/*
Requests that sent to this path is over the limit, please slow down.
*/
OPENDAL_RATE_LIMITED,
/*
The given file paths are same.
*/
OPENDAL_IS_SAME_FILE,
} opendal_code;

/*
Expand Down Expand Up @@ -120,7 +121,7 @@ typedef struct BlockingOperator BlockingOperator;
to check its validity by native boolean operator.
e.g. you could check by (!ptr) on a [`opendal_operator_ptr`]
*/
typedef const struct BlockingOperator* opendal_operator_ptr;
typedef const struct BlockingOperator *opendal_operator_ptr;

/*
The [`opendal_bytes`] type is a C-compatible substitute for [`Vec`]
Expand All @@ -129,8 +130,8 @@ typedef const struct BlockingOperator* opendal_operator_ptr;
to free the heap memory to avoid memory leak.
*/
typedef struct opendal_bytes {
const uint8_t* data;
uintptr_t len;
const uint8_t *data;
uintptr_t len;
} opendal_bytes;

/*
Expand All @@ -140,8 +141,8 @@ typedef struct opendal_bytes {
and the error code is NOT OPENDAL_OK.
*/
typedef struct opendal_result_read {
struct opendal_bytes* data;
enum opendal_code code;
struct opendal_bytes *data;
enum opendal_code code;
} opendal_result_read;

/*
Expand All @@ -150,8 +151,8 @@ typedef struct opendal_result_read {
corresponding error code.
*/
typedef struct opendal_result_is_exist {
bool is_exist;
enum opendal_code code;
bool is_exist;
enum opendal_code code;
} opendal_result_is_exist;

#ifdef __cplusplus
Expand All @@ -169,7 +170,7 @@ extern "C" {
the string.
* The `scheme` points to NULL, this function simply returns you a null opendal_operator_ptr
*/
opendal_operator_ptr opendal_operator_new(const char* scheme);
opendal_operator_ptr opendal_operator_new(const char *scheme);

/*
Free the allocated operator pointed by [`opendal_operator_ptr`]
Expand All @@ -191,8 +192,8 @@ void opendal_operator_free(opendal_operator_ptr op_ptr);
* If the `path` points to NULL, this function panics
*/
enum opendal_code opendal_operator_blocking_write(opendal_operator_ptr op_ptr,
const char* path,
struct opendal_bytes bytes);
const char *path,
struct opendal_bytes bytes);

/*
Read the data out from path into a [`Bytes`] blockingly by operator, returns
Expand All @@ -210,7 +211,7 @@ enum opendal_code opendal_operator_blocking_write(opendal_operator_ptr op_ptr,
* If the `path` points to NULL, this function panics
*/
struct opendal_result_read opendal_operator_blocking_read(opendal_operator_ptr op_ptr,
const char* path);
const char *path);

/*
Check whether the path exists.
Expand All @@ -231,12 +232,12 @@ struct opendal_result_read opendal_operator_blocking_read(opendal_operator_ptr o
* If the `path` points to NULL, this function panics
*/
struct opendal_result_is_exist opendal_operator_is_exist(opendal_operator_ptr op_ptr,
const char* path);
const char *path);

/*
Frees the heap memory used by the [`opendal_bytes`]
*/
void opendal_bytes_free(const struct opendal_bytes* self);
void opendal_bytes_free(const struct opendal_bytes *self);

#ifdef __cplusplus
} // extern "C"
Expand Down