Skip to content

Commit 8ed2efd

Browse files
committed
Set up Cargo to build libblas
1 parent b11d8c8 commit 8ed2efd

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/Cargo.lock
2+
/target

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "libblas"]
2+
path = libblas
3+
url = https://github.com/stainless-steel/liblapack.git

Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "libblas-sys"
3+
version = "0.0.1"
4+
authors = ["Ivan Ukhov <[email protected]>"]
5+
links = "libblas"
6+
build = "build.rs"

build.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#![feature(macro_rules)]
2+
3+
macro_rules! cmd(
4+
($name:expr) => (::std::io::process::Command::new($name));
5+
)
6+
7+
macro_rules! fmt(
8+
($($arg:tt)*) => (format_args!(::std::fmt::format, $($arg)*).as_slice());
9+
)
10+
11+
macro_rules! get(
12+
($name:expr) => (::std::os::getenv($name).unwrap());
13+
)
14+
15+
macro_rules! run(
16+
($command:expr) => (
17+
assert!($command.stdout(::std::io::process::InheritFd(1))
18+
.stderr(::std::io::process::InheritFd(2))
19+
.status().unwrap().success());
20+
);
21+
)
22+
23+
fn main() {
24+
let from = Path::new(get!("CARGO_MANIFEST_DIR")).join("libblas");
25+
let into = Path::new(get!("OUT_DIR"));
26+
27+
run!(cmd!("cmake").cwd(&into).arg(&from)
28+
.arg("-DCMAKE_Fortran_FLAGS='-O2 -frecursive -fPIC'"));
29+
30+
run!(cmd!("cmake").cwd(&into).arg("--build").arg(".")
31+
.arg("--target").arg("blas")
32+
.arg("--")
33+
.arg(fmt!("-j{}", get!("NUM_JOBS"))));
34+
35+
println!("cargo:rustc-flags=-L {}", into.join("lib").display());
36+
println!("cargo:rustc-flags=-l blas:static");
37+
}

libblas

Submodule libblas added at 2e0bc2d

src/lib.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! The library facilitates static linking with the [Basic Linear Algebra
2+
//! Subprograms][1].
3+
//!
4+
//! [1]: http://www.netlib.org/blas/
5+
6+
extern crate libc;
7+
8+
use libc::{c_char, c_double, c_int};
9+
10+
pub use dgemm_ as dgemm;
11+
pub use dgemv_ as dgemv;
12+
13+
#[link(name = "gfortran")]
14+
extern {
15+
/// http://www.netlib.org/lapack/explore-html/dc/da8/dgemv_8f.html
16+
fn dgemv_(trans: *const c_char, m: *const c_int, n: *const c_int,
17+
alpha: *const c_double, a: *const c_double, lda: *const c_int,
18+
x: *const c_double, incx: *const c_int, beta: *const c_double,
19+
y: *mut c_double, incy: *const c_int);
20+
21+
/// http://www.netlib.org/lapack/explore-html/d7/d2b/dgemm_8f.html
22+
fn dgemm_(transa: *const c_char, transb: *const c_char, m: *const c_int,
23+
n: *const c_int, k: *const c_int, alpha: *const c_double,
24+
a: *const c_double, lda: *const c_int, b: *const c_double,
25+
ldb: *const c_int, beta: *const c_double, c: *mut c_double,
26+
ldc: *const c_int);
27+
}

0 commit comments

Comments
 (0)