klutzy / rust-windows

work-in-progress Win32/Win64 wrapper for Rust (INACTIVE PROJECT: has no proper goal right now)
Other
57 stars 14 forks source link

Cargofy the project #15

Closed engstad closed 9 years ago

engstad commented 9 years ago

I'm by far not a Cargo expert, but here's an initial attempt that at least builds the library and executable.

alexchandel commented 9 years ago

@engstad You should remove the .gitattributes and the Cargo.lock file.

Also, the Cargo.toml should have as many keys as possible from the Package metadata requirements for crates.io.

That means you should remove the tags field, and add at least a readme, license, repository, and keywords field.

engstad commented 9 years ago

One thing missing with Cargo is the windres compilation of the resource file. Now, I can't actually test this, since I don't have it in my path (and I need to update my msys2 setup), so I will let someone else take care of it. However, I believe we'll need to make use of a build.rs script, such as the following:

#![allow(unstable)]

use std::io::{stderr, Command};
use std::os;

fn main() {
    let out_dir = os::getenv("OUT_DIR").unwrap();

    let status = Command::new("windres").arg("src/hello.rc")
        .arg(format!("{}/hello.rc.o", out_dir))
        .status();

    match status {
        Ok(_) => println!("cargo:rustc-flags=-C link-args={}/hello.rc.o", out_dir),
        Err(e) => stderr().write(format!("warning: failed to run windres: {}", e).as_bytes()).unwrap()
    }
}

Feel free to experiment with it (add build = "build.rs" to Cargo.toml).

engstad commented 9 years ago

@alexchandel Thanks, I will let the maintainer take care of that!

alexchandel commented 9 years ago

@engstad The additional Cargo.toml file in the examples directory is unnecessary. As the Cargo Project Layout guide details, files in the examples/ directory are automatically considered binaries and built as tests. Any other integration-like tests should go in tests/. The repository as a whole shouldn't have more than a single Cargo.toml, and a library shouldn't have a Cargo.lock anywhere.

Can I suggest squashing these commits too? Since a few files were added and subsequently deleted.

engstad commented 9 years ago

@alexchandel Cargo.toml is needed because the example needs to have an additional build step (see above).

My git-fu is not very strong. How would I squash them and push it upstream?

alexchandel commented 9 years ago

My bad. Are you sure the library and example build with just cargo build and cargo test?

Your branch hasn't been pulled yet so you're free to rewrite history. You probably want to rewrite the commit message so just git reset --soft HEAD~3 or however many, then git commit again. You'll have to force push the branch to your GitHub repo.

edit: but the changes will automatically be reflected in this PR.

engstad commented 9 years ago

Thanks! I'll do that.

Yes, it compiles and runs fine (cargo clean && cargo build && cargo run). The only problem is that the menu is not working, because of the windres issue.

engstad commented 9 years ago

@alexchandel Squashed!

alexchandel commented 9 years ago

Looks good to me.

I'd still think examples with their own Cargo are strange, since its toml doesn't build it any better than the master one.

alexchandel commented 9 years ago

@klutzy ready to merge?