Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e89e9be
# This is a combination of 3 commits.
tgross35 Nov 9, 2022
5ccd335
Create Cargo.toml
tgross35 Nov 10, 2022
c30e85a
Add workflow to upload book
tgross35 Nov 11, 2022
d47893a
Work on encryption example
tgross35 Jan 4, 2023
22b6d1e
Progress on demo encryption plugin
tgross35 Jan 4, 2023
353db7a
Basic macro for system variable working
tgross35 Jan 5, 2023
ea06c90
Work on plugin! macro
tgross35 Jan 5, 2023
a05fbb9
Basic plugin compiles (untested)
tgross35 Jan 6, 2023
709be00
Update plugin examples
tgross35 Jan 11, 2023
a42486f
Example runs, but panics on dst len
tgross35 Jan 11, 2023
ae50c66
Clean up dbg statements
tgross35 Jan 12, 2023
4b98a8a
Add helper scripts
tgross35 Jan 12, 2023
ee8e9a1
Added proc macro to register plugins
tgross35 Jan 18, 2023
9e20b7f
Reworked some example organization
tgross35 Jan 19, 2023
49f5a06
Work on service_sql
tgross35 Jan 19, 2023
313a5ca
Work on rows iter
tgross35 Jan 20, 2023
59b11b1
Work on iterator
tgross35 Jan 20, 2023
b8c38de
Work on clevis plugin
tgross35 Feb 3, 2023
b0fc96d
Fix sys crate rebuilds
tgross35 Feb 4, 2023
9d018ff
Work on mariadb sql service
tgross35 Feb 4, 2023
2419c54
Static plugin generation now works
tgross35 Feb 5, 2023
f109804
Fixes for clippy
tgross35 Feb 5, 2023
7bffbb3
Implement logging via the 'log' crate
tgross35 Feb 5, 2023
432072d
Variable parsers
tgross35 Feb 5, 2023
b58aa98
Work on proc macro tests
tgross35 Feb 6, 2023
39994aa
Update 'register_plugin' to accept system variables
tgross35 Feb 6, 2023
c99a2c6
Updates for clippy
tgross35 Feb 6, 2023
fceadaf
Update for sysvar output in proc macros
tgross35 Feb 7, 2023
51132db
Updates to workflows and docs
tgross35 Feb 7, 2023
dab9219
Start plugin updates
tgross35 Feb 8, 2023
6041d6c
Wrapped up generic interfaces
tgross35 Feb 8, 2023
adecad3
Merge pull request #4 from pluots/rust-wip
tgross35 Feb 8, 2023
d147215
Fix doctests
tgross35 Feb 9, 2023
5d22e96
Proc macros working with full generic args
tgross35 Feb 9, 2023
48111df
System variables working and validated (atomic, const string, string)
tgross35 Feb 9, 2023
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
629 changes: 629 additions & 0 deletions .dockerignore

Large diffs are not rendered by default.

178 changes: 178 additions & 0 deletions .github/workflows/validation-rust.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
---

# Main "useful" actions config file
# Cache config comes from https://github.com/actions/cache/blob/main/examples.md#rust---cargo
# actions-rs/toolchain configures rustup
# actions-rs/cargo actually runs cargo

on:
push:
branches:
- rust
# pull_request:

name: Rust Validation

jobs:
check:
name: "Check (cargo check)"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
rust/target/
CMakeFiles/
CMakeCache.txt
CPackConfig.cmake
CPackSourceConfig.cmake
CTestTestfile.cmake
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: sudo apt-get update && sudo apt-get install cmake
- uses: dtolnay/rust-toolchain@stable
- run: cargo check --manifest-path rust/Cargo.toml

test:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest] #, windows-latest, macos-latest]
include:
- os: ubuntu-latest
name: linux
# - os: windows-latest
# name: windows
# - os: macos-latest
# name: mac

name: "Test on ${{ matrix.name }} (cargo test)"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
rust/target/
CMakeFiles/
CMakeCache.txt
CPackConfig.cmake
CPackSourceConfig.cmake
CTestTestfile.cmake
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: sudo apt-get update && sudo apt-get install cmake
- uses: dtolnay/rust-toolchain@stable
- run: cargo test --manifest-path rust/Cargo.toml
env:
RUST_BACKTRACE: "1"


fmt:
name: "Format (cargo fmt)"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
rust/target/
CMakeFiles/
CMakeCache.txt
CPackConfig.cmake
CPackSourceConfig.cmake
CTestTestfile.cmake
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- run: cargo fmt --manifest-path rust/Cargo.toml --all -- --check

clippy:
name: "Clippy (cargo clippy)"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
rust/target/
CMakeFiles/
CMakeCache.txt
CPackConfig.cmake
CPackSourceConfig.cmake
CTestTestfile.cmake
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: sudo apt-get update && sudo apt-get install cmake
- uses: dtolnay/rust-toolchain@nightly
with:
components: clippy
- run: cargo clippy --manifest-path rust/Cargo.toml -- -D warnings

doc:
name: "Docs (cargo doc) & Pub"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
rust/target/
CMakeFiles/
CMakeCache.txt
CPackConfig.cmake
CPackSourceConfig.cmake
CTestTestfile.cmake
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: sudo apt-get update && sudo apt-get install cmake
- uses: dtolnay/rust-toolchain@stable
# test docs for everything
- name: Test build all docs
run: cargo doc --manifest-path rust/Cargo.toml --no-deps
# create docs for the crate we care about
- name: Build docs for publish
run: |
rm -rf target/doc/ rust/target/doc/
cargo doc --manifest-path rust/mariadb/Cargo.toml --no-deps
cargo doc --manifest-path rust/bindings/Cargo.toml --no-deps
- run: |
echo `pwd`/rust/target/doc >> $GITHUB_PATH
# fake index.html so github likes us
echo "<meta http-equiv=\"refresh\" content=\"0; url=mariadb\">" > rust/target/doc/index.html
- name: Deploy GitHub Pages
run: |
git worktree add gh-pages
git config user.name "Deploy from CI"
git config user.email ""
cd gh-pages
# Delete the ref to avoid keeping history.
git update-ref -d refs/heads/gh-pages
rm -rf *
mv ../rust/target/doc/* .
git add .
git commit -m "Deploy $GITHUB_SHA to gh-pages"
git push --force --set-upstream origin gh-pages
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,7 @@ tests/mariadb-client-test
versioninfo_dll.rc
versioninfo_exe.rc
win/packaging/ca/symlinks.cc

# rust output
rust/target
Cargo.lock
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# MariaDB: Rust Support Fork

This is a fork of [MariaDB server](https://github.com/MariaDB/server) with the
goal of experimenting with a Rust plugin API. It is a work in progress,
everything here should be considered unstable.

View docs for the Rust API here:
<https://pluots.github.io/mariadb-server/mariadb/index.html>.


Code status:
------------

Expand Down
11 changes: 11 additions & 0 deletions docker_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# docker run -it -v $(pwd):/build/server ubuntu
apt-get update
apt-get build-dep mariadb-server
apt-get install -y build-essential libncurses5-dev gnutls-dev bison zlib1g-dev ccache g++ cmake ninja-build vim wget

cd build
mkdir build-mariadb-server-debug
cd build-mariadb-server-debug
cmake ../server -DCONC_WITH_{UNITTEST,SSL}=OFF -DWITH_UNIT_TESTS=OFF -DCMAKE_BUILD_TYPE=Debug -DWITH_SAFEMALLOC=OFF -DWITH_SSL=bundled -DMYSQL_MAINTAINER_MODE=OFF -G Ninja

# cmake --build . --parallel 4
1 change: 0 additions & 1 deletion include/mysql/plugin_auth_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,3 @@ typedef struct st_plugin_vio
} MYSQL_PLUGIN_VIO;

#endif

1 change: 1 addition & 0 deletions rust/.clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc-valid-idents = ["MySQL", "MariaDB"]
6 changes: 6 additions & 0 deletions rust/.rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
imports_granularity = "Module"
newline_style = "Unix"
group_imports = "StdExternalCrate"
format_code_in_doc_comments = true
format_macro_bodies = true
format_macro_matchers = true
13 changes: 13 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Define our crates within a workspace

[workspace]

members = [
"bindings",
"mariadb",
"macros",
"examples/keymgt-basic",
"examples/keymgt-debug",
"examples/encryption",
"plugins/keymgt-clevis",
]
65 changes: 65 additions & 0 deletions rust/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Quick test for our example plugins, build against the current repo but runs
# with the published 10.11 image
#
# ```
# # Build the image. Change the directory (../) if not building in `rust/`
# docker build -f Dockerfile ../ --tag mdb-plugin-ex
#
# # Run the container, select default plugins as desired
# docker run --rm -e MARIADB_ROOT_PASSWORD=example --name mdb-plugin-ex-c \
# mdb-plugin-ex \
# --plugin-maturity=experimental \
# --plugin-load=libbasic \
# --plugin-load=libencryption
# --plugin-load=libkeymgt_debug
#
# # Enter a SQL console
# docker exec -it mdb-plugin-ex-c mysql -pexample
#
# # Install desired plugins
# INSTALL PLUGIN basic_key_management SONAME 'libbasic.so';
# INSTALL PLUGIN encryption_example SONAME 'libencryption.so';
# INSTALL PLUGIN debug_key_management SONAME 'libkeymgt_debug.so';
#
# # Stop server
# docker stop mdb-plugin-ex-c
# ```

# use nighlty image for faster builds
FROM rustlang/rust:nightly AS build

ENV CARGO_UNSTABLE_SPARSE_REGISTRY=true
WORKDIR /build

RUN apt-get update \
# build requirements
&& apt-get install -y cmake clang bison \
&& mkdir /output

COPY . .

WORKDIR /build/rust

RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=target \
cargo build \
# -p basic
# -p encryption
# --release \
# && cp target/release/*.so /output
&& cp target/debug/*.so /output

# RUN cp target/debug/*.so /output

RUN export RUST_BACKTRACE=1

FROM mariadb:10.11-rc

# Deb utils
RUN apt-get update \
&& apt-get install -y xxd less vim-tiny binutils

COPY --from=build /output/* /usr/lib/mysql/plugin/

# create database db; use db; create table t1 (id int) encrypted=yes;
# flush tables t1 for export;
33 changes: 33 additions & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Rust support for MariaDB

The purpose of this module is to be able to write plugins for MariaDB in Rust.

## Building

The Rust portion of this repository does not yet integrate with the main MariaDB
CMake build system to statically link plugins (adding this is a goal).

To build dynamically, simply run `cargo build` within this `/rust` directory.

## Testing with Docker


```sh
# Build the image. Change the directory (../) if not building in `rust/`
docker build -f Dockerfile ../ --tag mdb-plugin-ex

# Run the container
docker run --rm -e MARIADB_ROOT_PASSWORD=example --name mdb-plugin-ex-c \
mdb-plugin-ex \
--plugin-maturity=experimental
# --plugin-load=libbasic \
# --plugin-load=libencryption
# --plugin-load=libdebug_key_management

# Enter a SQL console
docker exec -it mdb-plugin-ex-c mysql -pexample

# Install desired plugins
INSTALL PLUGIN basic_key_management SONAME 'libbasic.so';
INSTALL PLUGIN encryption_example SONAME 'libencryption_example.so';
```
10 changes: 10 additions & 0 deletions rust/bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "mariadb-sys"
version = "0.1.0"
edition = '2021'


[build-dependencies]
bindgen = "0.63.0"
cmake = "0.1"
doxygen-rs = "0.2"
Loading