harfbuzz / harfbuzz_rs

A fully safe Rust wrapper for the harfbuzz text shaping library.
MIT License
52 stars 21 forks source link

Using the master branch as a dependency and running the example is broken on M2. #36

Open asibahi opened 9 months ago

asibahi commented 9 months ago

Hello.

My machine is a MacBook Air M2.

I am on the latest Rust release (1.75.0).

This is my dependencies section in Cargo.toml

[dependencies]
harfbuzz_rs = { git = "https://github.com/harfbuzz/harfbuzz_rs.git" }

I am using the example code given in the crate. Regardless, this is my code:

use std::error::Error;
use harfbuzz_rs::*;

fn main() -> Result<(), Box<dyn Error>> {
    let path =
        "/Users/abdulrahmansibahi/Documents/rust/mimiron/mimiron/fonts/YanoneKaffeesatz-Medium.ttf";
    let index = 0; //< face index in the font file
    let face = Face::from_file(path, index)?;
    let font = Font::new(face);

    let buffer = UnicodeBuffer::new().add_str("Hello World!");
    let output = shape(&font, buffer, &[]);

    let positions = output.get_glyph_positions();
    let infos = output.get_glyph_infos();

    for (position, info) in positions.iter().zip(infos) {
        let gid = info.codepoint;
        let cluster = info.cluster;
        let x_advance = position.x_advance;
        let x_offset = position.x_offset;
        let y_offset = position.y_offset;        

        println!(
            "gid: {:?}. cluster: {:?}. x_advance: {:?}, x_offset: {:?} y_offset: {:?}",
            gid, cluster, x_advance, x_offset, y_offset
        );
    }

    Ok(())
}

And this is the error I get :

error.txt

I asked in the Rust Community Discord server and it apparently works on other, non-Apple, systems. I haven't tried myself as I .. don't have other systems.

This same code works on the Crates.io version.

Edit: This is the last good commit that works for me : https://github.com/harfbuzz/harfbuzz_rs/commit/15d1c2a7b661c3a9f5f72132177f56ea19d2abdf , pre removing the harfbuzz_sys crate as a dependency.

asibahi commented 5 months ago

Tried cloning the repo into my machine instead of linking from GitHub, and faced the same issue.

A bit of googling about the not found symbols, I found this Stack Overflow Answer, which seems related. but I don't know enough on how to solve it myself. Edit2? I found that the reason is that OS X on ARM puts the Core Foundation libraries somewhere else. The meson file handles that, but I could not figure out how to translate the conditions into build.rs or how to invoke the meson file from there.

Edit: commenting out this part in build.rs made it compile and run the example successfully:

    if target.contains("apple") {
        cfg.define("HAVE_CORETEXT", "1");
    }