Skip to content

Commit

Permalink
update cpp documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Avery committed Jun 21, 2024
1 parent 4b1d6a1 commit 0bc9de8
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 29 deletions.
31 changes: 21 additions & 10 deletions languages/cpp/CMakeBuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,30 @@ Cmake is used to build the c++ Bitwarden client library. Output should be placed

One should be in the root directory of the c++ wrapper (the same level where is CMakeLists.txt placed). Paths of the three libraries should be placed inside the cmake build command:

$ mkdir build
$ cd build
$ cmake .. -DNLOHMANN=/path/to/include/nlohmann -DBOOST=/path/to/include/boost -DTARGET=relative/path/to/libbitwarden_c
$ cmake --build .
```bash
mkdir build
cd build
cmake .. -DNLOHMANN=/path/to/include/nlohmann -DBOOST=/path/to/include/boost -DTARGET=relative/path/to/libbitwarden_c
cmake --build .
```

## Example

### macOS

## Example
#### Install prerequisites

macOS:
```bash
brew install cmake
brew install boost
brew install nlohmann-json
```

$ mkdir build
$ cd build
$ cmake .. -DNLOHMANN=/opt/hombrew/include -DBOOST=/opt/homebrew/include -DTARGET=../../target/release/libbitwarden_c.dylib
$ cmake --build .
#### Build

```bash
mkdir -p build
cd build
cmake .. -DNLOHMANN=/opt/homebrew/include -DBOOST=/opt/homebrew/include -DTARGET=../../target/release/libbitwarden_c.dylib
cmake --build .
```
90 changes: 71 additions & 19 deletions languages/cpp/ExampleUse.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# EXAMPLES


## PREREQUISITES

### BITWARDEN Libraries
One should have two libraries at the same path:

Have the two Bitwarden libraries at the same path:

- `BitwardeClient`
- `bitwarden_c`

It should look like `libBitwardeClient.dylib` and `libbitwarden_c.dylib` for the macOS.
For each OS the library files will be the following:

For Linux: `libBitwardeClient.so` and `libbitwarden_c.so`
For Windows: `BitwardeClient.dll` and `bitwarden_c.dll`
- macOS: `libBitwardeClient.dylib` and `libbitwarden_c.dylib`
- Linux: `libBitwardeClient.so` and `libbitwarden_c.so`
- Windows: `BitwardeClient.dll` and `bitwarden_c.dll`

Follow the [cmake build guide](CMakeBuild.md) to create the libraries locally.

### INCLUDE directory

`include` directory contains:

- `BitwardenLibrary.h`
- `BitwardenClient.h`
- `BitwardenSettings.h`
Expand All @@ -25,15 +30,17 @@ For Windows: `BitwardeClient.dll` and `bitwarden_c.dll`
- `schemas.hpp`

### Other libraries
- `nlohmann-json` (https://github.com/nlohmann/json)
- `boost` (https://www.boost.org/)

- `nlohmann-json` (<https://github.com/nlohmann/json>)
- `boost` (<https://www.boost.org/>)

### COMPILING

One could use g++/clang++ for compiling.
Use g++/clang++ for compiling.

Example of the folder structure (macOS):

```text
--root
--build
`libBitwardenClient.dylib`
Expand All @@ -48,23 +55,68 @@ Example of the folder structure (macOS):
--`schemas.hpp`
--examples
--`Wrapper.cpp`
```

Add the environment path for the Bitwarden libraries.

For macOS:

```bash
export DYLD_LIBRARY_PATH=/path/to/your/library:$DYLD_LIBRARY_PATH
```

For Linux:

```bash
export LD_LIBRARY_PATH=/path/to/your/library:$LD_LIBRARY_PATH
```

1. $ export ACCESS_TOKEN=<"access-token">
2. $ export ORGANIZATION_ID=<"organization-id">
3. $ export DYLD_LIBRARY_PATH=/path/to/your/library:$DYLD_LIBRARY_PATH
For Windows:

The last step is neccessary to add the path for the dynamic library (macOS).
For the Linux one should use:
$ export LD_LIBRARY_PATH=/path/to/your/library:$LD_LIBRARY_PATH
For the Windows:
$ set PATH=%PATH%;C:\path\to\your\library
```shell
set PATH=%PATH%;C:\path\to\your\library
```

4. $ cd examples
5. $ clang++ -std=c++20 -I../include -I/path/to/include/nlohmann -I/path/to/include/boost -L../build/ -o MyBitwardenApp Wrapper.cpp -lBitwardenClient -ldl
Export environment variables used in `Wrapper.cpp`:

```bash
export ACCESS_TOKEN=<"access-token">
export ORGANIZATION_ID=<"organization-id">
export API_URL=http://localhost:4000
export IDENTITY_URL=http://localhost:33656
```

Compile:

```bash
cd examples
clang++ -std=c++20 -I../include -I/path/to/include/nlohmann -I/path/to/include/boost -L../build/ -o MyBitwardenApp Wrapper.cpp -lBitwardenClient -ldl
```

for Windows `-ldl` should be excluded,

The result is `MyBitwardenApp` in the `examples` directory, and one can run it from the `examples` directory:

6. $ ./MyBitwardenApp
```bash
./MyBitwardenApp
```

## Example

### macOS

Export:

```bash
export DYLD_LIBRARY_PATH=/path/to/your/library:$DYLD_LIBRARY_PATH
export ACCESS_TOKEN=<"access-token">
export ORGANIZATION_ID=<"organization-id">
export API_URL=http://localhost:4000
export IDENTITY_URL=http://localhost:33656
```

Compile:

```bash
clang++ -std=c++20 -I../include -I/opt/homebrew/include -L../build/ -o MyBitwardenApp Wrapper.cpp -lBitwardenClient -ldl
```

0 comments on commit 0bc9de8

Please sign in to comment.