Skip to content

Basic template. #6

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

Closed
wants to merge 7 commits into from
Closed
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
93 changes: 93 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Linux
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '$'
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Always
66 changes: 66 additions & 0 deletions .github/workflows/ci_meson.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: ci_meson

on:
push:
paths:
- "**.cc"
- "**.h"
- "**.build"
- ".github/workflows/ci_meson.yml"

jobs:
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: 3.7
- run: |
pip install meson
sudo apt -yq update
sudo apt install -yq --no-install-recommends ninja-build
- run: meson setup build
- run: meson test -C build -v
- uses: actions/upload-artifact@v1
if: failure()
with:
name: Linux_Meson_Testlog
path: build/meson-logs/testlog.txt

macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: 3.7
- run: |
brew install gcc ninja
pip install meson
- run: meson setup build
- run: meson test -C build -v
- uses: actions/upload-artifact@v1
if: failure()
with:
name: MacOS_Meson_Testlog
path: build/meson-logs/testlog.txt

windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: 3.7

- run: |
cinst -y ninja
pip install meson
- run: meson setup build
- run: meson test -C build -v
- uses: actions/upload-artifact@v1
if: failure()
with:
name: Windows_Meson_Testlog
path: build/meson-logs/testlog.txt
27 changes: 27 additions & 0 deletions .github/workflows/ci_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Auto Release

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:
release:
name: Auto Release by Tags
runs-on: ubuntu-18.04

steps:
- name: Checkout Repository
uses: actions/checkout@master

- name: GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,6 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# Meson build target
build/
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,53 @@
# casbin-cpp
# Casbin Library for C/C++

![workflow](https://github.com/casbin/casbin-cpp/workflows/ci_meson/badge.svg)

This is a powerful and efficient open-source access control library for C/C++ projects. It provides support for enforcing authorization based on various [access control models](https://en.wikipedia.org/wiki/Computer_security_model).

## Usage

If you want to try it, consider installing the `meson` build system, and `ninja` must also be installed with it. For example, on the fedora platform, run `dnf install meson`.

Then:

```bash
git clone git@github.com:casbin/casbin-cpp.git
# or `git clone https://github.com/casbin/casbin-cpp.git`
cd casbin-cpp

# start build
meson build
ninja -C build # -j8
```

### For Developers

```bash
# start install
cd build
meson install
```

Now it should be added to your system.

### For Contributors

In addition, the two subcommands `release` and `format` are provided for easy use.

Just run `ninja -C build <subcommand>`.

_**Note:**_

- Since the `format` script relies on `clang-format`, consider installing it.
- At least make sure that the code is formatted and can be built locally before submission.

## License

This project is licensed under the [Apache 2.0 license](LICENSE).

## Contact

If you have any issues or feature requests, please contact us. PR is welcomed.

- <https://github.com/casbin/casbin-cpp/issues>
- Tencent QQ group: [546057381](//shang.qq.com/wpa/qunwpa?idkey=8ac8b91fc97ace3d383d0035f7aa06f7d670fd8e8d4837347354a31c18fac885)
Empty file added include/casbin.h
Empty file.
5 changes: 5 additions & 0 deletions include/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
libcasbin_headers = [
'casbin.h',
]

install_headers(libcasbin_headers, subdir : 'casbin')
Empty file added lib/casbin.cc
Empty file.
20 changes: 20 additions & 0 deletions lib/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
libcasbin_sources = [
'casbin.cc',
]

deps = []

libcasbin = library('casbin', libcasbin_sources, version: meson.project_version(),
include_directories: include_dirs,
dependencies: deps, install: true,
)

pkg = import('pkgconfig')
pkg.generate(libraries: [ libcasbin ],
version: meson.project_version(),
name: 'casbin',
description: 'Casbin Authorization Library',
subdirs: 'casbin')

libcasbin_dep = declare_dependency(include_directories: include_dirs,
link_with: libcasbin, dependencies: deps)
30 changes: 30 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
project('libcasbin', ['cpp', 'c'],
version : '0.1.0',
meson_version: '>= 0.50.0',
default_options : ['warning_level=3'])


config_h = configuration_data()
config_h.set_quoted('PACKAGE_VERSION', meson.project_version())
configure_file(
output: 'config.h',
configuration: config_h,
)
add_project_arguments([
'-I' + meson.build_root(),
], language: ['cpp', 'c'])

include_dirs = include_directories('include', 'lib', '.')

subdir('include')
subdir('lib')

run_target(
'format',
command: ['scripts/format.sh']
)

run_target(
'release',
command: ['scripts/release.sh', meson.project_name(), meson.project_version()]
)
4 changes: 4 additions & 0 deletions scripts/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

clang-format -i "${MESON_SOURCE_ROOT}"/lib/*.cc
clang-format -i "${MESON_SOURCE_ROOT}"/include/*.h
30 changes: 30 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

if ! [ "$MESON_BUILD_ROOT" ]; then
echo "This can only be run via meson, exiting!"
exit 1
fi

PKGVER=$1-$2
DEST=${MESON_BUILD_ROOT}
DIST=$DEST/dist/$PKGVER
SRC=${MESON_SOURCE_ROOT}

cd "${MESON_SOURCE_ROOT}"
mkdir -p "${DIST}"

ginst() {
cp -rf $@ "${DIST}"
}

ginst \
meson.build \
LICENSE \
README.md \
scripts \
lib \
include \

# packaging
cd "${DEST}"/dist
tar cJvf $PKGVER.tar.xz $PKGVER