ethercat icon indicating copy to clipboard operation
ethercat copied to clipboard

How to configure `Ethercat master` in `build.rs`?

Open rise0chen opened this issue 2 years ago • 5 comments

I want to configure Ethercat master in build.rs of my project.

fn main() -> Result<(), Box<dyn std::error::Error>> {
    use std::process::Command;
    use std::{env, fs};
    let dir = fs::canonicalize("./vendor/etherlab")?;
    env::set_var("ETHERCAT_PATH", &dir);
    env::set_current_dir(&dir)?;
    Command::new(format!("{}/bootstrap", dir.display())).current_dir(&dir).status().unwrap();
    Command::new(format!("{}/configure", dir.display()))
        .current_dir(&dir)
        .arg("--disable-8139too")
        .arg("--enable-igb")
        .arg("--enable-cycles")
        .arg("--enable-rtdm")
        .arg("--enable-hrtimer")
        .arg("--with-rtai-dir=/usr/realtime")
        .arg("--with-linux-dir=/usr/src/linux")
        .status()
        .unwrap();
    Ok(())
}

It should run build.rs of my project first, and then run build.rs of ethercat-sys. But in fact, build.rs of ethercat-sys is first. Do you have any suggestions?

rise0chen avatar May 11 '23 02:05 rise0chen

Hi, not really, other than that you could use the pregenerated-bindings (make sure you use the compatible version of the master), then the master is not needed at all.

birkenfeld avatar May 12 '23 15:05 birkenfeld

No, I not want to use pregenerated-bindings.

I have success to run this project by manual configure. I run bootstrap , configure and set ETHERCAT_PATH env, then run cargo run, it can work. I just wat to configure it by build.rs.

rise0chen avatar May 12 '23 15:05 rise0chen

As far as I know, there is no way to have build.rs or anything else run before the dependencies build.rs.

birkenfeld avatar May 12 '23 16:05 birkenfeld

Can I call ethercat-sys/build.rs in my build.rs?

rise0chen avatar May 12 '23 16:05 rise0chen

That wouldn't help since at that time ethercat-sys/build.rs already has run.

birkenfeld avatar May 14 '23 06:05 birkenfeld