-
Notifications
You must be signed in to change notification settings - Fork 16
/
build.rs
87 lines (78 loc) · 2.52 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2018 First Rust Competition Developers.
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::env;
use std::fs;
#[cfg(unix)]
use std::os::unix::fs::symlink;
#[cfg(windows)]
use std::os::windows::fs::symlink_dir;
use std::path::*;
/// announce our lib dir with a symlink cargo-frc to copy
fn announce_lib() {
#![allow(unreachable_code)] // compile-dependent panic for not windows or unix platform
let mut lib_path = PathBuf::new();
lib_path.push(env::var("CARGO_MANIFEST_DIR").expect("Couldn't read manifest dir env var."));
lib_path.push(LIB_DIR);
let mut symlink_path = env::temp_dir();
let mut flag_path = symlink_path.clone();
symlink_path.push("frc-libs");
flag_path.push("frc-flag");
println!("cargo:rerun-if-changed={}", flag_path.display());
fs::write(flag_path, b"flag").expect("Could not write to temp flag file");
fs::remove_file(symlink_path.clone()).ok(); //ignore the err
#[cfg(unix)]
{
symlink(lib_path, symlink_path).expect("Could not create lib symlink");
}
#[cfg(windows)]
{
symlink_dir(lib_path, symlink_path).expect("Could not create lib symlink");
}
#[cfg(not(any(windows, unix)))]
{
panic!("Platform is not Windows or UNIX!");
}
}
const LIB_DIR: &str = "lib";
const LIB_LIST: &[&str] = &[
"FRC_NetworkCommunication",
"NiFpga",
"NiFpgaLv",
"niriodevenum",
"niriosession",
"NiRioSrv",
"RoboRIO_FRC_ChipObject",
"visa",
"wpiHal",
"wpiutil",
];
/// Tell cargo to link our libs
fn link() {
for lib in LIB_LIST.iter() {
println!("cargo:rustc-link-lib=dylib={}", lib);
}
let path = env::current_dir().unwrap();
println!(
"cargo:rustc-link-search=native={}/{}",
path.display(),
LIB_DIR
);
}
// For some reason, this makes the build script always run on compile
// While not ideal, this is kind of necessary for cargo-frc to do its thing
// If you plan to have multiple FRC projects and deploy them randomly
// (How do I know I have a symlink to the right lib version?)
// TODO(Lytigas) replace this hack with a file cargo-frc will touch on run
fn always_run() {
#[cfg(feature = "dev")]
println!("cargo:rerun-if-changed=*");
}
fn main() {
always_run();
announce_lib();
link();
}