build.rs 2.04 KB
Newer Older
Thomas Daede's avatar
Thomas Daede committed
1 2
// build.rs

Luca Barbato's avatar
Luca Barbato committed
3
#[cfg(all(target_arch = "x86_64", feature = "nasm"))]
4
extern crate nasm_rs;
Thomas Daede's avatar
Thomas Daede committed
5

6
#[allow(unused_imports)]
7
use std::env;
Luca Barbato's avatar
Luca Barbato committed
8
use std::fs;
9
use std::path::Path;
10

11 12 13 14 15 16 17 18 19 20 21 22 23
#[allow(dead_code)]
fn rerun_dir<P: AsRef<Path>>(dir: P) {
    for entry in fs::read_dir(dir).unwrap() {
        let entry = entry.unwrap();
        let path = entry.path();
        println!("cargo:rerun-if-changed={}", path.to_string_lossy());

        if path.is_dir() {
            rerun_dir(path);
        }
    }
}

Thomas Daede's avatar
Thomas Daede committed
24
fn main() {
25
    #[cfg(all(target_arch = "x86_64", feature = "nasm"))] {
Luca Barbato's avatar
Luca Barbato committed
26 27
        use std::fs::File;
        use std::io::Write;
28 29 30 31
        let out_dir = env::var("OUT_DIR").unwrap();
        {
            let dest_path = Path::new(&out_dir).join("config.asm");
            let mut config_file = File::create(dest_path).unwrap();
32
            config_file.write(b"	%define private_prefix rav1e\n").unwrap();
33 34 35
            config_file.write(b"	%define ARCH_X86_32 0\n").unwrap();
            config_file.write(b" %define ARCH_X86_64 1\n").unwrap();
            config_file.write(b"	%define PIC 1\n").unwrap();
36
            config_file.write(b" %define STACK_ALIGNMENT 16\n").unwrap();
37 38 39
            if cfg!(target_os="macos") {
              config_file.write(b" %define PREFIX 1\n").unwrap();
            }
40 41 42 43
        }
        let mut config_include_arg = String::from("-I");
        config_include_arg.push_str(&out_dir);
        config_include_arg.push('/');
44 45 46 47 48
        nasm_rs::compile_library_args(
            "rav1easm",
            &[
                "src/x86/data.asm",
                "src/x86/ipred.asm",
49
                "src/x86/itx.asm",
50
                "src/x86/mc.asm",
51
                "src/x86/me.asm",
52 53
                "src/x86/sad_sse2.asm",
                "src/x86/sad_avx.asm"
54 55 56
            ],
            &[&config_include_arg, "-Isrc/"]
        );
57
        println!("cargo:rustc-link-lib=static=rav1easm");
58 59
        rerun_dir("src/x86");
        rerun_dir("src/ext/x86");
60 61
    }

62 63 64
    if cfg!(windows) && cfg!(feature = "decode_test") {
        panic!("Unsupported feature on this platform!");
    }
Thomas Daede's avatar
Thomas Daede committed
65
}