gtk-rs / gtk-rs-core

Rust bindings for GNOME libraries
https://gtk-rs.org/gtk-rs-core
MIT License
287 stars 114 forks source link

Unable to cross-compile cairo-rs from macOS to Windows #181

Closed flowjo-isaach closed 3 years ago

flowjo-isaach commented 3 years ago

I was unsuccessful at cross-compiling from macOS to Windows when using cairo-rs. I attempted to follow what I could from this document: https://github.com/gtk-rs/gtk-rs.github.io/blob/1dbd8c3ded7e83910426bb4af10d312c85a957be/docs-src/tutorial/cross.md.

I ran the following command: PKG_CONFIG_ALLOW_CROSS=1 cargo build --target=x86_64-pc-windows-gnu --release Error log is in this github gist: https://gist.github.com/flowjo-isaach/165d7f9cb808f79c1092c0291d58bc78

Any help would be greatly appreciated!

.cargo/config:

[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
ar = "x86_64-w64-mingw32-gcc-ar"

main.rs:

use cairo_rs::{Context, Format, ImageSurface};

fn main() {
    let surface = ImageSurface::create(Format::ARgb32, 256, 256).expect("Can't create surface");
    let cr = Context::new(&surface).unwrap();
    // Examples are in 1.0 x 1.0 coordinate space                                                                                          
    cr.scale(1.0, 1.0);

    // Drawing code goes here                                                                                                                                  
    cr.set_line_width(1.);
    cr.set_source_rgb(0.0, 0.0, 0.0);
    cr.rectangle(64.5, 64.5, 128., 128.);
    cr.stroke();

    let mut file = File::create("file.png").expect("Couldn't create 'file.png'");
    match surface.write_to_png(&mut file) {
        Ok(_) => println!("file.png created"),
        Err(_) => println!("Error create file.png"),
    }
}
sdroege commented 3 years ago

Can you provide the full cargo build -vvvvvv output from a clean build?

flowjo-isaach commented 3 years ago

@sdroege : sure, here's the clean build: command: cargo clean && cargo build --target=x86_64-pc-windows-gnu --release output: https://gist.github.com/flowjo-isaach/607e6379b90434f9be0c3ac1c943bc56

sdroege commented 3 years ago

You forgot -vvvvv :)

flowjo-isaach commented 3 years ago

my bad 😓 command: cargo clean && cargo build -vvvvv --target=x86_64-pc-windows-gnu --release output: https://gist.github.com/flowjo-isaach/f2302c424c8af12e702e432e82c7ab09

sdroege commented 3 years ago

This is the relevant code here: https://github.com/rust-lang/pkg-config-rs/blob/master/src/lib.rs#L340-L352

You need to configure your environment correctly for cross-compilation with pkg-config.

wwstory commented 1 year ago

hi, can you provide a simple configuration method? after some attempts, i build with --target=i686-pc-windows-gnu by mingw-w64 on linux, I couldn't configure it successfully.