Skip to content

Update build test #16

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

Open
wants to merge 3 commits into
base: rust
Choose a base branch
from
Open
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 rust/bridge/handler_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ typedef struct handler_bridge_vt {


/** Wrapper that can expose a C vtable as a C++ class */
class handler_bridge: public handler {
class handler_bridge final: public handler {
public:
/** The vtable that we defer to for all method calls */
const handler_bridge_vt *const vt;
Expand Down
44 changes: 35 additions & 9 deletions rust/examples/storage-csv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,38 @@ use std::path::Path;

use mariadb::log::debug;
use mariadb::plugin::{License, Maturity};
use mariadb::storage::{Handler, Handlerton, Mode, OpenOp, StorageResult};
use mariadb::storage::{Handler, Handlerton, Mode, OpenOp, StorageResult, TableFlags};
use mariadb::{register_plugin_storage, MemRoot, TableShare};

register_plugin_storage! {
name: "EXAMPLE_RUST_CSV",
name: "example_rust_csv",
author: "Trevor Gross",
description: "Reimplementation of ha_tina for debugging",
license: License::Gpl,
maturity: Maturity::Experimental,
version: "0.1",
handlerton: ExampleHton,
handlerton: CsvHton,
}

struct ExampleHton;
struct ExampleHandler {}
/// Data file extension
const DATA_EXT: &str = ".CSV";
/// Files for repair and update
const REPAIR_UPDATE_EXT: &str = ".CSN";
/// Meta file
const META_EXT: &str = ".CSM";

impl Handlerton for ExampleHton {
type Handler = ExampleHandler;
struct CsvHton;
struct CsvHandler {}

impl Handlerton for CsvHton {
type Handler = CsvHandler;
type SavePoint = ();

const TABLEFILE_EXTENSIONS: &'static [&'static str] = &[DATA_EXT, REPAIR_UPDATE_EXT, META_EXT];
}

impl Handler for ExampleHandler {
type Handlerton = ExampleHton;
impl Handler for CsvHandler {
type Handlerton = CsvHton;

// #[mariadb::dbug::instrument]
fn new(table: &TableShare, mem_root: MemRoot) -> Self {
Expand All @@ -40,7 +48,25 @@ impl Handler for ExampleHandler {
todo!()
}

fn table_flags(&self) -> TableFlags {
TableFlags::NO_TRANSACTIONS
| TableFlags::REC_NOT_IN_SEQ
| TableFlags::NO_AUTO_INCREMENT
| TableFlags::BINLOG_ROW_CAPABLE
| TableFlags::BINLOG_STMT_CAPABLE
| TableFlags::CAN_EXPORT
| TableFlags::CAN_REPAIR
| TableFlags::SLOW_RND_POS
}

fn write_row(buf: &CStr) {
// Nothing to do here
}
}

impl Drop for CsvHandler {
fn drop(&mut self) {
// assert!();
// assert!();
}
}
25 changes: 11 additions & 14 deletions rust/mariadb-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,6 @@ fn make_bindings() {
.write_to_file(out_path.join("bindings.rs"))
.expect("couldn't write bindings");

// Tell cargo to rerun if header files change. We walkdir to find only headers
// because using every file was too slow.
for path in include_paths.iter() {
for header_file in walkdir::WalkDir::new(path)
.into_iter()
.filter_map(Result::ok)
.map(walkdir::DirEntry::into_path)
.filter(|p| p.extension() == Some("h".as_ref()))
{
println!("cargo:rerun-if-changed={}", header_file.display());
}
}

success = true;
break;
}
Expand Down Expand Up @@ -127,7 +114,7 @@ fn include_paths_from_cmake() -> Option<Vec<PathBuf>> {
};
eprintln!("using paths from cmake");

Some(vec![PathBuf::from(src_dir), PathBuf::from(dst_dir)])
dbg!(Some(vec![PathBuf::from(src_dir), PathBuf::from(dst_dir)]))
} else {
eprintln!("cmake environment not set, skipping");
None
Expand Down Expand Up @@ -165,6 +152,9 @@ fn make_bindings_with_includes(include_paths: &[PathBuf]) -> Result<Bindings, Er
.header("src/handler_helper.h")
// Fix math.h double defines
.parse_callbacks(Box::new(BuildCallbacks))
.parse_callbacks(Box::new(
bindgen::CargoCallbacks::new().rerun_on_header_files(true),
))
.clang_args(incl_args)
.clang_arg("-xc++")
.clang_arg("-std=c++17")
Expand Down Expand Up @@ -213,6 +203,13 @@ fn make_bindings_with_includes(include_paths: &[PathBuf]) -> Result<Bindings, Er
// dynamic thing).
.allowlist_item("MYSQL_.*")
.allowlist_type("sql_service_st")
// Types that fail bindgen's layout tests we make opaque
.opaque_type("I_P_List")
.opaque_type("I_P_List_null_counter")
.opaque_type("I_P_List_no_push_back")
.opaque_type("MDL_ticket")
.opaque_type("Lex_extended_charset_extended_collation_attrs")
.opaque_type("Lex_extended_charset_extended_collation_attrs_st")
// Finish the builder and generate the bindings.
.generate()
.map_err(Into::into)
Expand Down
4 changes: 2 additions & 2 deletions rust/mariadb/src/plugin/storage_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use super::wrapper::{init_common, PluginMeta};
use crate::storage::{Handler, Handlerton};
use crate::{bindings, MemRoot, TableShare};

/// Trait implemented by the macro for an easy
/// Internal trait implemented by the macro for an easy way to bridge to the C interface.
pub trait HandlertonMeta: Handlerton + PluginMeta {
/// This function should return the vtable, which should be located in statics.
/// This function should return the vtable, which should be located in static data.
fn get_vtable() -> &'static bindings::handler_bridge_vt;
}

Expand Down
4 changes: 2 additions & 2 deletions rust/mariadb/src/plugin/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::{env, ptr};
use super::{Init, InitError};
use crate::{bindings, configure_logger};

/// Meta that we generate in the proc macro, which we can use to get information about our type in
/// wrappers
/// Internal meta that we generate in the proc macro, which we can use to get information
/// about our type in wrappers.
pub trait PluginMeta {
const NAME: &'static str;
}
Expand Down
2 changes: 1 addition & 1 deletion rust/mariadb/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod handler;
mod handlerton;

pub use error::{StorageError, StorageResult};
pub use handler::{Handler, Mode, OpenOp};
pub use handler::{Handler, Mode, OpenOp, TableFlags};
pub use handlerton::{Handlerton, HandlertonCtx};

use crate::bindings;
Expand Down
Loading