Skip to content
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

Generate Rusty wrapper by procedural macro, merge lapack crate #12

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

termoshtt
Copy link
Member

Depends on #11

  • Replace Python script to generate rusty wrapper at lapack/bin by proc-macro crate lapack-derive
  • Introduce cargo-workspace for adding lapack-derive crate
  • Integrate lapack crate features into lapack-sys crate

How proc-macro works

This PR adds #[lapack] attribute for every extern "C" block generated by #11 :

#[lapack]                
extern "C" {               
    pub fn dgetrs_(                    
        trans: *const c_char,
        n: *const c_int,                
        nrhs: *const c_int, 
        A: *const f64,       
        lda: *const c_int, 
        ipiv: *const c_int,
        B: *mut f64,     
        ldb: *const c_int,            
        info: *mut c_int, 
    );                                
}

lapack_derive::lapack expands it into following:

extern "C" {               
    pub fn dgetrs_(                    
        trans: *const c_char,
        n: *const c_int,                
        nrhs: *const c_int, 
        A: *const f64,       
        lda: *const c_int, 
        ipiv: *const c_int,
        B: *mut f64,     
        ldb: *const c_int,            
        info: *mut c_int, 
    );                                
}

pub unsafe fn dgetrs(        
    trans: c_char,                                         
    n: c_int,        
    nrhs: c_int,                
    A: &[f64],        
    lda: c_int,        
    ipiv: &[c_int],        
    B: &mut [f64],        
    ldb: c_int,        
    info: &mut c_int        
) {              
    dgetrs_(        
        &trans,        
        &n,               
        &nrhs,          
        A.as_ptr(),        
        &lda,                    
        ipiv.as_ptr(),        
        B.as_mut_ptr(),        
        &ldb,             
        info                  
    )                          
}     

In lapack crate, it is done by the Python script and generated Rust code is committed. This PR proposes merging lapack crate into lapack-sys crate. You can confirm the generated result by cargo doc --no-deps.

Conversion rule

  • *const T is converted into &[T] by default
    • Whitelisted names e.g. uplo, trans, and so on, are regarded as T, and pass by &value to FFI.
    • The list is implemented in lapack_derive::is_value function
  • *mut T is converted into &mut [T] by default
    • Whitelisted names e.g. info, rcond, are regarded as &mut T
    • The list is implemented in lapack_derive::is_mut_ref function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant