Skip to content

Commit 42d5594

Browse files
author
Guillaume Fraux
committed
Generate the right symlink for lumol.so
1 parent a82089b commit 42d5594

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
target
22
Cargo.lock
3+
lumol.so

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "lumol-py"
33
version = "0.1.0"
44
authors = ["Guillaume Fraux <guillaume.fraux@ens.fr>"]
5+
build = "build.rs"
56

67
[dependencies]
78
lumol = {git = "https://github.com/lumol-org/lumol", rev = "11503ea"}

build.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use std::env;
2+
use std::path::{Path, PathBuf};
3+
use std::io::Result;
4+
use std::fs;
5+
6+
#[cfg(unix)]
7+
fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> Result<()> {
8+
use std::os::unix::fs;
9+
return fs::symlink(src, dst);
10+
}
11+
12+
#[cfg(windows)]
13+
fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> Result<()> {
14+
use std::os::windws::fs;
15+
return fs::symlink_file(src, dst);
16+
}
17+
18+
fn dynlib_ext() -> &'static str {
19+
if cfg!(target_os="macos") {
20+
".dylib"
21+
} else if cfg!(target_os="linux") {
22+
".so"
23+
} else if cfg!(windows) {
24+
".dll"
25+
} else {
26+
panic!("Missing dynamic library extension for this platform. Please edit 'build.rs'");
27+
}
28+
}
29+
30+
fn main() {
31+
let profile = env::var("PROFILE").unwrap();
32+
let libname = String::from("liblumol_py") + dynlib_ext();
33+
let library = PathBuf::from("target").join(profile).join(libname);
34+
let link = Path::new("./lumol.so");
35+
36+
if link.symlink_metadata().is_ok() {
37+
fs::remove_file(link).expect("Could not remove symbolic link");
38+
}
39+
40+
symlink(library, link).expect("Could not create symbolic link");
41+
}

lumol.so

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)