Skip to content
Permalink
Browse files

Rip out all the proc-macro work so it compiles on musl

  • Loading branch information
palfrey committed Oct 27, 2019
1 parent 3d489bb commit a55db0681a8aad8c27233f7a7fe993951e6755c7
Showing with 88 additions and 106 deletions.
  1. +25 −78 Cargo.lock
  2. +6 −3 Cargo.toml
  3. +7 −1 notes.txt
  4. +49 −22 src/common.rs
  5. +1 −2 src/main.rs

Some generated files are not rendered by default. Learn more.

@@ -7,8 +7,8 @@ edition = "2018"
[dependencies]
odbc = "0.14"
env_logger = "0.7"
structopt = { version = "0.3", default-features = false }
failure = { version = "0.1", default-features = false, features = ["derive"] }
clap = "2.33"
failure = { version = "0.1", default-features = false }
exitcode = "1.1"

[dev-dependencies]
@@ -21,4 +21,7 @@ predicates = "1"
opt-level = "z"
lto = true
codegen-units = 1
panic = 'abort'
panic = 'abort'

[patch.crates-io]
odbc-sys = { path = './odbc-sys' }
@@ -1,3 +1,9 @@
POSTGRES_SERVER=localhost POSTGRES_PORT=32768 POSTGRES_USERNAME=postgres POSTGRES_PASSWORD= RUST_BACKTRACE=1 POSTGRES_DRIVER=/usr/local/Cellar/psqlodbc/10.03.0000_1/lib/psqlodbca.so SQLITE_DRIVER=/usr/local/Cellar/sqliteodbc/0.9996/lib/libsqlite3odbc-0.9996.dylib cargo watch -s "cargo test -- --nocapture"

https://stackoverflow.com/questions/35069027/docker-wait-for-postgresql-to-be-running
https://stackoverflow.com/questions/35069027/docker-wait-for-postgresql-to-be-running

musl static can't use proc_macro https://github.com/rust-lang/rust/issues/59302

https://doc.rust-lang.org/edition-guide/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.html

RUSTFLAGS="-C target-feature=+crt-static" cargo run --target=x86_64-unknown-linux-musl
@@ -1,31 +1,61 @@
use failure::Fail;
use clap::{App, Arg};
use odbc::DiagnosticRecord;
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
pub struct Opts {
#[structopt(required = true, long, short, help = "Connection string")]
pub connection_string: String,

#[structopt(long, short, help = "SQL Query (default: no query)")]
pub sql_text: Option<String>,

#[structopt(short = "t", long = "timeout", help = "Timeout (seconds)")]
pub timeout_seconds: Option<u64>,

#[structopt(short, long, help = "Quiet mode")]
pub quiet: bool,

#[structopt(
short = "p",
long = "pause",
help = "Pause between checks (seconds)",
default_value = "3"
)]
pub pause_seconds: u64,
}

pub fn parse_args() -> Opts {
let matches = App::new("wait-for-db")
.arg(
Arg::with_name("connection-string")
.short("c")
.long("connection-string")
.required(true)
.takes_value(true)
.help("Connection string"),
)
.arg(
Arg::with_name("sql-text")
.short("s")
.long("sql-text")
.takes_value(true)
.help("SQL Query (default: no query)"),
)
.arg(
Arg::with_name("timeout")
.short("t")
.long("timeout")
.takes_value(true)
.help("Timeout (seconds)"),
)
.arg(
Arg::with_name("quiet")
.short("q")
.long("quiet")
.help("Quiet mode"),
)
.arg(
Arg::with_name("pause")
.short("p")
.long("pause")
.takes_value(true)
.help("Pause between checks (seconds)")
.default_value("3"),
).get_matches();
Opts {
connection_string: matches.value_of("connection-string").unwrap().to_string(),
sql_text: matches.value_of("sql-text").and_then(|s| Some(s.to_string())),
timeout_seconds: matches.value_of("timeout-seconds").and_then(|s| u64::from_str_radix(s, 10).ok()),
quiet: matches.is_present("quiet"),
pause_seconds: matches.value_of("pause").and_then(|s| u64::from_str_radix(s, 10).ok()).unwrap(),
}
}

#[cfg(test)]
impl Opts {
pub fn new() -> Self {
@@ -61,12 +91,9 @@ pub enum DbErrorLifetime {
Temporary,
}

#[derive(Debug, Fail)]
#[derive(Debug)]
pub enum DbErrorType {
#[fail(display = "odbc error: {}", error)]
OdbcError { error: DiagnosticRecord },

#[fail(display = "postgres error")]
PostgresError,
}

@@ -2,13 +2,12 @@ use env_logger::Builder;
use std::env;
use std::thread;
use std::time::{Duration, Instant};
use structopt::StructOpt;

use wait_for_db::common;
use wait_for_db::odbc;

fn main() {
let opt = common::Opts::from_args();
let opt = common::parse_args();
Builder::new()
.parse_filters(&env::var("WAIT_DB_LOG").unwrap_or("odbc=off".to_string()))
.init();

0 comments on commit a55db06

Please sign in to comment.
You can’t perform that action at this time.