1 unstable release
0.1.0 | Feb 28, 2025 |
---|
#212 in Build Utils
154 downloads per month
355KB
7K
SLoC
fortranc-rs
A library for Cargo build scripts to compile a set of Fortran/assembly files into a static archive for cargo to link into the crate being built. This crate does not compile code itself; it calls out to the default compiler for the platform.
This is not ready for usage yet, use for hacking only.
The code is pretty much copied from cc-rs project.
License
This project is licensed under either of
- Apache License, Version 2.0, (license-apache or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (license-mit or https://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in cc-rs by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
A library for Cargo build scripts to compile a set of Fortran files into a static archive for Cargo to link into the crate being built. This crate does not compile code itself; it calls out to the default compiler for the platform. This crate is courtesy of the work done in cc-rs crate.
Example
First, you'll want to both add a build script for your crate (build.rs
) and
also add this crate to your Cargo.toml
via:
[build-dependencies]
fortranc = "*"
Next up, you'll want to write a build script like so:
// build.rs
fortranc::Build::new()
.file("foo.f90")
.file("bar.f90")
.compile("foo");
And that's it! Running cargo build
should take care of the rest and your Rust
application will now have the Fortran files foo.f90
and bar.f90
compiled into a file
named libfoo.a
. If the Fortran files contain
subroutine foo() bind(C)
print *, 'hello from fortran'
end subroutine
and
function bar() bind(C) result(i)
integer(4) :: i
i = 5
end function
you can call them from Rust by declaring them in your Rust code like so:
unsafe extern "C" {
fn foo();
fn bar() -> i32;
}
pub fn call() {
unsafe {
foo();
bar();
}
}
fn main() {
call();
}