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

C API bindings for libthreescalers.{so,a} #100

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
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
50 changes: 50 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ xml-response = ["serde-xml-rs", "serde", "chrono"]
# HTTP mapping rules
rest-mappings = ["regex", "lazy_static"]
rest-mappings-serde = ["serde"]
# C API
capi = []

[dependencies]
percent-encoding = "^2"
Expand Down Expand Up @@ -74,3 +76,51 @@ required-features = ["curl-easy2"]
serde_json = "^1.0"
itertools = "^0.10"
rand = "^0.8"

[profile.release]
lto = true
codegen-units = 1

[package.metadata.capi.header]
# Used as header file name. By default this is equal to the crate name.
# The name can be with or without the header filename extension `.h`
#name = "new_name"
# Install the header into a subdirectory with the name of the crate. This
# is enabled by default, pass `false` or "" to disable it.
#subdirectory = "libthreescalers-0.8/threescalers"
# Generate the header file with `cbindgen`, or copy a pre-generated header
# from the `assets` subdirectory. By default a header is generated.
#generation = true
# Can be use to disable header generation completely.
# This can be used when generating dynamic modules instead of an actual library.
#enabled = true

[package.metadata.capi.pkg_config]
# Used as the package name in the pkg-config file and defaults to the crate name.
#name = "libthreescalers"
# Used as the package description in the pkg-config file and defaults to the crate description.
description = "3scale API client library"
# Used as the package version in the pkg-config file and defaults to the crate version.
#version = "1.2.3"
# Used as the Requires field in the pkg-config file, if defined
#requires = "gstreamer-1.0, gstreamer-base-1.0"
# Used as the Requires.private field in the pkg-config file, if defined
#requires_private = "gobject-2.0, glib-2.0 >= 2.56.0, gmodule-2.0"
# Strip the include search path from the last n components, useful to support installing in a
# subdirectory but then include with the path. By default it is 0.
#strip_include_path_components = 1

[package.metadata.capi.library]
# Used as the library name and defaults to the crate name. This might get
# prefixed with `lib` depending on the target platform.
#name = "new_name"
# Used as library version and defaults to the crate version. How this is used
# depends on the target platform.
#version = "1.2.3"
# Used to install the library to a subdirectory of `libdir`.
#install_subdir = "gstreamer-1.0"
# Used to disable versioning links when installing the dynamic library
#versioning = false
# Add `-Cpanic=abort` to the RUSTFLAGS automatically, it may be useful in case
# something might panic in the crates used by the library.
rustflags = "-C panic=abort -C link-args=-Wl,-Map=libthreescalers.map"
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
out/usr/lib64/libthreescalers.so:
cargo cinstall --destdir=out --prefix=/usr --libdir=/usr/lib64

.PHONY: so-build
so-build: out/usr/lib64/libthreescalers.so
strip -s out/usr/lib64/libthreescalers.so.*.*

.PHONY: so-install
so-install: out/usr/lib64/libthreescalers.so
sudo chown -R root: out
sudo cp -av out/* /

.PHONY: so-clean
so-clean:
-sudo rm -rf out/

.PHONY: so-distclean
so-distclean: so-clean
sudo rm -rf /usr/lib64/libthreescalers*
sudo rm -rf /usr/lib64/pkgconfig/threescalers.pc
-sudo rmdir /usr/lib64/pkgconfig
sudo rm -rf /usr/include/threescalers
-sudo rmdir /usr/include
155 changes: 155 additions & 0 deletions cbindgen.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# This is a template cbindgen.toml file with all of the default values.
# Some values are commented out because their absence is the real default.
#
# See https://github.com/eqrion/cbindgen/blob/master/docs.md#cbindgentoml
# for detailed documentation of every option here.



language = "C"



############## Options for Wrapping the Contents of the Header #################

# header = "/* Text to put at the beginning of the generated file. Probably a license. */"
header = "// SPDX-License-Identifier: Apache-2.0"
# trailer = "/* Text to put at the end of the generated file */"
# include_guard = "my_bindings_h"
# pragma_once = true
# autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */"
include_version = false
# namespace = "my_namespace"
namespaces = []
using_namespaces = []
sys_includes = []
includes = []
no_includes = false
after_includes = ""




############################ Code Style Options ################################

braces = "SameLine"
line_length = 100
tab_width = 2
documentation = true
documentation_style = "auto"
line_endings = "LF" # also "CR", "CRLF", "Native"




############################# Codegen Options ##################################

style = "both"
sort_by = "Name" # default for `fn.sort_by` and `const.sort_by`
usize_is_size_t = true



[defines]
# "target_os = freebsd" = "DEFINE_FREEBSD"
# "feature = serde" = "DEFINE_SERDE"
# "feature = capi" = "DEFINE_CAPI"
"feature = std" = "DEFINE_STD"
"feature = http-types" = "DEFINE_HTTP_TYPES"
"feature = xml-response" = "DEFINE_XML_RESPONSE"


[export]
include = []
exclude = []
# prefix = "CAPI_"
item_types = []
renaming_overrides_prefixing = false



[export.rename]



[export.body]


[export.mangle]


[fn]
rename_args = "None"
# must_use = "MUST_USE_FUNC"
# no_return = "NO_RETURN"
# prefix = "START_FUNC"
# postfix = "END_FUNC"
args = "auto"
sort_by = "Name"




[struct]
rename_fields = "None"
# must_use = "MUST_USE_STRUCT"
derive_constructor = false
derive_eq = false
derive_neq = false
derive_lt = false
derive_lte = false
derive_gt = false
derive_gte = false




[enum]
rename_variants = "None"
# must_use = "MUST_USE_ENUM"
add_sentinel = false
prefix_with_name = false
derive_helper_methods = false
derive_const_casts = false
derive_mut_casts = false
# cast_assert_name = "ASSERT"
derive_tagged_enum_destructor = false
derive_tagged_enum_copy_constructor = false
enum_class = true
private_default_tagged_enum_constructor = false




[const]
allow_static_const = true
allow_constexpr = false
sort_by = "Name"




[macro_expansion]
bitflags = false






############## Options for How Your Rust library Should Be Parsed ##############

[parse]
parse_deps = false
# include = []
exclude = []
clean = false
extra_bindings = []



[parse.expand]
crates = []
all_features = true
default_features = true
features = []
14 changes: 14 additions & 0 deletions src/capi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::prelude::v1::*;

mod ffi_cow;
pub use ffi_cow::fficow_free;
pub use ffi_cow::{FFICow, FFIStr, FFIString};

mod c_slice;
pub use c_slice::{CSlice, CSliceMut};

pub mod encoding;
pub mod version;

#[cfg(feature = "rest-mappings")]
pub mod mapping_rule;
Loading