Call make before cargo build


#1

Hi all,

I have a makefile

to run in order to build a library before to call cargo. Is there any way to do this ?

I tried build.rs but no success. Is build.rs the right way?

Thanks a lot.


#2

What did you try in build.rs?


#3

To run make but I don’t know from where the commands started form build.rs are run.


#4

Yes, build.rs right way. You can try use https://crates.io/crates/make-cmd crate to simpify things. If you see errors, post them here.


#6

Another solution may be to do it in the opposite order: call cargo build from the makefile.


#7

Actually, I solved it using an env variable which is passed to the makefile, and allow conditional compilation:

    // compile luacall library: OS dependant
    if cfg!(target_os = "linux") {
        // makefile is using a special env variable
        Command::new("make")
                .env("LUA_DIR", lua_dir)
                .args(&["-f", "src/lua/luacall_linux.mak"])
                .status()
                .expect("failed to make!");
    }

and it works pretty well (at least for Linux !)