makspll/bevy_mod_scripting

Incompatible types when compiling on Arm64

Closed this issue · 18 comments

I am facing a similar set of errors to #61 with bevy 0.11.2 and bevy_mod_scripting commit 8bf3796 with the lua_script_api flag enabled

cargo run
    Updating git repository `https://github.com/makspll/bevy_mod_scripting`
   Compiling bevy_script_api v0.3.0 (https://github.com/makspll/bevy_mod_scripting?rev=8bf3796#8bf37962)
error[E0599]: no variant or associated item named `Pairs` found for enum `LuaMetaMethod` in the current scope
   --> /Users/videah/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/8bf3796/bevy_script_api/src/lua/std.rs:317:45
    |
317 |         methods.add_meta_method(MetaMethod::Pairs, |ctx, s, _: ()| {
    |                                             ^^^^^ variant or associated item not found in `LuaMetaMethod`

error[E0308]: `?` operator has incompatible types
    --> /Users/videah/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/8bf3796/bevy_script_api/src/generated.rs:4501:17
     |
4501 |     #[languages(on_feature(lua))]
     |                 ^^^^^^^^^^^^^^^ expected `BVec4`, found `BVec4A`
     |
     = note: `?` operator cannot convert from `BVec4A` to `BVec4`
     = note: this error originates in the macro `impl_lua_newtype` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
    --> /Users/videah/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/8bf3796/bevy_script_api/src/generated.rs:4501:17
     |
4501 |     #[languages(on_feature(lua))]
     |                 ^^^^^^^^^^^^^^^
     |                 |
     |                 expected `BVec4A`, found `BVec4`
     |                 arguments to this function are incorrect
     |
note: associated function defined here
    --> /Users/videah/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/8bf3796/bevy_script_api/src/wrappers.rs:38:16
     |
38   |         pub fn new(b: $type_) -> Self {
     |                ^^^ ---------
     |
    ::: /Users/videah/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/8bf3796/bevy_script_api/src/generated.rs:5050:17
     |
5050 |     #[languages(on_feature(lua))]
     |                 --------------- in this macro invocation
     = note: this error originates in the macro `impl_lua_newtype` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0308, E0599.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `bevy_script_api` (lib) due to 3 previous errors

My Cargo.toml looks like this:

[package]
name = "myrrh"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

# Enable a small amount of optimization in debug mode
[profile.dev]
opt-level = 1

# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"]
opt-level = 3

[dependencies]
bevy = { version = "0.11.2", features = ["dynamic_linking"] }
bevy_mod_scripting = { git = "https://github.com/makspll/bevy_mod_scripting", rev = "8bf3796", version = "0.3.0", features = ["luajit", "teal", "lua_script_api"] }

Can you try using:

bevy_mod_scripting = { git = "https://github.com/makspll/bevy_mod_scripting", rev = "8bf3796", features = ["luajit", "teal", "lua_script_api"] }

I am able to run cargo run --example bevy_api_lua --features=lua54,lua_script_api on main, is it maybe that the old version is being picked up with that statement?

I get the same error I'm afraid, even with a cargo clean 😢

Interesting, I see why I can run it, the issue comes from luajit! Pairs doesn't exist with that feature:

    #[cfg(any(
        feature = "lua54",
        feature = "lua53",
        feature = "lua52",
        feature = "luajit52",
    ))]
    Pairs,

I will adjust the pipeline to compile check with all the lua feature combinations and push a fix soon

That's now merged into main, and luajit should work with the lua script api feature

I'm running into the same issue:

error[E0308]: `?` operator has incompatible types
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:4518:9
     |
4518 |         ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `BVec4`, found `BVec4A`
     |
     = note: `?` operator cannot convert from `BVec4A` to `BVec4`

This happens with both the lua54 and luajit features.

Cargo.toml:

[package]
name = "bevyworld"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy_mod_scripting = { git = "https://github.com/makspll/bevy_mod_scripting.git", rev = "7590248", features = ["luajit","lua_script_api"] }
bevy_mod_scripting_lua = { git = "https://github.com/makspll/bevy_mod_scripting.git", rev = "7590248"}
bevy = { version = "0.11.2", features = ["dynamic_linking", "serialize","bevy_asset","bevy_core_pipeline","bevy_pbr","bevy_render","bevy_sprite","bevy_winit","filesystem_watcher","hdr","multi-threaded","tonemapping_luts","ktx2","zstd"] , default-features = false }
rand = "0.8.5"
rand_distr = "0.4.3"

I get this error on both a new project and when running several of the example projects. Is there a solution?

Thanks!

Hi @CyanBlob I am able to compile with the below Cargo.toml:

[package]
name = "bevyworld"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy_mod_scripting = { git = "https://github.com/makspll/bevy_mod_scripting.git", rev = "7590248", features = [
    "luajit",
    "lua_script_api",
] }
bevy = { version = "0.11.2", features = [
    "dynamic_linking",
    "serialize",
    "bevy_asset",
    "bevy_core_pipeline",
    "bevy_pbr",
    "bevy_render",
    "bevy_sprite",
    "filesystem_watcher",
    "hdr",
    "multi-threaded",
    "tonemapping_luts",
    "ktx2",
    "zstd",
], default-features = false }

and the following main.rs:

use bevy::app::AppExit;

use bevy::prelude::*;
use bevy_mod_scripting::prelude::*;

**use bevy_mod_scripting::api::lua::{bevy::LuaBevyAPIProvider, RegisterForeignLuaType};**

#[derive(Component, Default, Reflect)]
#[reflect(Component)]
pub struct MyComponent {
    quat: Quat,
    vec2: Vec2,
    usize: usize,
    f32: f32,
    mat3: Mat3,
    option_vec3: Option<Vec3>,
    vec_of_option_bools: Vec<Option<bool>>,
    option_vec_of_bools: Option<Vec<bool>>,
}

fn main() -> std::io::Result<()> {
    let mut app = App::new();

    app.add_plugins(DefaultPlugins)
        .add_plugins(ScriptingPlugin)
        .register_type::<MyComponent>()
        // note the implementation for Option is there, but we must register `LuaProxyable` for it
        .register_foreign_lua_type::<Option<Vec3>>()
        .register_foreign_lua_type::<Vec<Option<bool>>>()
        .register_foreign_lua_type::<Option<bool>>()
        .register_foreign_lua_type::<Option<Vec<bool>>>()
        .add_script_host::<LuaScriptHost<()>>(PostUpdate)
        .add_api_provider::<LuaScriptHost<()>>(Box::new(LuaBevyAPIProvider))
        .add_systems(Startup,
            |world: &mut World| {

                let entity = world.spawn(())
                    .insert(MyComponent {
                        usize: 5,
                        vec2: Vec2::new(1.0, 2.0),
                        f32: 6.7,
                        mat3: Mat3::from_cols(
                            Vec3::new(1.0, 2.0, 3.0),
                            Vec3::new(4.0, 5.0, 6.0),
                            Vec3::new(7.0, 8.0, 9.0),
                        ),
                        quat: Quat::from_xyzw(1.0, 2.0, 3.0, 4.0),
                        option_vec3: None,
                        vec_of_option_bools: vec![Some(true), None, Some(false)],
                        option_vec_of_bools: Some(vec![true, true, true]),
                    }).id();

                // run script
                world.resource_scope(|world, mut host: Mut<LuaScriptHost<()>>| {
                    host.run_one_shot(
                        r#"
                        function table_to_string(t)
                            local result = "["
                            for k,v in pairs(t) do
                                result = result .. string.format("%s:%s,",k,v)
                            end
                            return result .. "]"
                        end

                        function once()
                            
                            -- the api provides us with 3 globals
                            print(entity)
                            print(script)
                            print(world)

                            -- we first retrieve ID's for our component and resource by their short name (long name/full path also work)
                            local my_component_type = world:get_type_by_name("MyComponent")

                            -- then ask the world to give us a reference to `MyComponent` on the entity we just spawned
                            -- resources work the same way, but we use `get_resource` instead of `get_component`
                            -- the comp object is resolved to a `bevy_script_api::script_ref::ReflectValue` which implements UserData.
                            -- we can use a custom proxy instead (by implementing LuaProxyable), but this is the simplest way to get started.
                            local comp = world:get_component(entity, my_component_type)
                            print("Before script: ", comp)

                            print("============")

                            -- the index metamethod on ReflectValue's uses bevy's reflection mechanism on top of some custom sub-reflection logic to
                            -- allow reflecting inside Options, Vectors etc. 
                            -- when we index into ReflectValue's we either get back a custom proxy or another ReflectValue

                            -- the LuaBevyAPIProvider provides us custom proxies for many bevy types as well as std types.
                            -- all of these implementations can be overridden via the bevy TypeRegistry
                            comp.usize = 2
                            print("comp.usize after assigning to 2: ", comp.usize)
                            
                            -- Option's get converted to nil or the value inside
                            print("comp.option_vec3 before: ", comp.option_vec3)
                            comp.option_vec3 = Vec3.new(2,1,3)
                            print("comp.option_vec3 after: ", comp.option_vec3)

                            -- reflection via index is indexed starting at 1, unlike in Rust to match Lua's indexing
                            print("comp.option_vec3[1] before: ", comp.option_vec3[1])
                            comp.option_vec3[1] = 5
                            print("comp.option_vec3[1] after: ", comp.option_vec3[1])

                            print("============")

                            -- Vec<T> references get converted to a custom proxy `LuaVec<T>` which is 
                            -- also assignable via lua tables 

                            print("comp.vec_of_option_bools before: ", table_to_string(comp.vec_of_option_bools))
                            comp.vec_of_option_bools = {true,false,true}
                            print("comp.vec_of_option_bools after assignment: ", table_to_string(comp.vec_of_option_bools))

                            print("comp.vec_of_option_bools[1] before: ", comp.vec_of_option_bools[1])
                            comp.vec_of_option_bools[1] = false
                            print("comp.vec_of_option_bools[1] after: ", comp.vec_of_option_bools[1])

                            -- there are some additional methods available on LuaVec proxies imitating the Vec<T> api
                            print("comp.vec_of_option_bools before insert: ", table_to_string(comp.vec_of_option_bools))
                            comp.vec_of_option_bools:insert(1,nil)
                            print("comp.vec_of_option_bools after insert: ", table_to_string(comp.vec_of_option_bools))

                            print("comp.vec_of_option_bools before push: ", table_to_string(comp.vec_of_option_bools))
                            comp.vec_of_option_bools:push(false)
                            print("comp.vec_of_option_bools after push: ", table_to_string(comp.vec_of_option_bools))

                            print("comp.vec_of_option_bools len after push: ", #comp.vec_of_option_bools)

                            print("comp.vec_of_option_bools before pop: ", table_to_string(comp.vec_of_option_bools))
                            print(comp.vec_of_option_bools:pop())
                            print("comp.vec_of_option_bools after pop: ", table_to_string(comp.vec_of_option_bools))
                            
                            print("the pairs inside comp.vec_of_option_bools: ")             
                            for k,v in pairs(comp.vec_of_option_bools) do
                                print(string.format(" - %s:%s",k,v))
                            end
                            
                            comp.vec_of_option_bools:clear()
                            print("comp.vec_of_option_bools after clear: ", table_to_string(comp.vec_of_option_bools))

                            print("comp.vec_of_option_bools len after clear: ", #comp.vec_of_option_bools)
                            print("============")

                            print("comp.option_vec_of_bools before: ", table_to_string(comp.option_vec_of_bools))
                            print(comp.option_vec_of_bools:pop())
                            print("comp.option_vec_of_bools after pop: ", table_to_string(comp.option_vec_of_bools))
  

                            print("comp.option_vec_of_bools len after pop: ", #comp.option_vec_of_bools)

                            print("the pairs inside comp.option_vec_of_bools: ")
                            for k,v in pairs(comp.option_vec_of_bools) do
                                print(string.format(" - %s:%s",k,v))
                            end

                            print("============")

                            local complex_vec_op = Vec3.new(0,1,0):any_orthonormal_vector() + comp.mat3.x_axis 
                            print("(0,1,0).any_orthonormal_vector() + mat3.x_axis is: ", complex_vec_op) 
                            
                            local new_mat3 = Mat3.from_cols(Vec3.new(1,0,0),Vec3.new(0,1,0),Vec3.new(0,0,-1))
                            print("new_mat3 is:", new_mat3)

                            comp.vec2 = comp.vec2 + comp.vec2
                            comp.usize = comp.vec2:min_element()
                            comp.f32 = comp.f32 + comp.f32 + comp.vec2:min_element()
                            comp.vec2 = Vec2.new(2,1)
                            comp.quat = Quat.from_xyzw(3,2,1,4)
                            comp.mat3.x_axis = Vec3.new(69,69,69)

                            print("============")

                            -- this is an example of something impossible to achieve with plain bevy reflection under the hood
                            comp.mat3[1][1] = 42

                            -- now let's retrieve these again to see if we actually changed their values permanently
                            comp = world:get_component(entity,my_component_type)
                            
                            print("After script:")
                            print(comp)
                        end
                        "#
                        .as_bytes(),
                        "script.lua",
                        entity,
                        world,
                        LuaEvent {
                            hook_name: "once".to_owned(),
                            args: (),
                            recipients: Recipients::All,
                        },
                    )
                    .expect("Something went wrong in the script!");
                });

                world.send_event(AppExit)
            },
        );

    app.run();

    Ok(())
}

Note I removed the direct dependency on bevy_mod_scripting_lua and changed the import structure but I don't think that was causing any issues either.

Which examples are giving you trouble exactly ?

Same issue:

error[E0308]: `?` operator has incompatible types
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:4518:9
     |
4518 |         ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `BVec4`, found `BVec4A`
     |
     = note: `?` operator cannot convert from `BVec4A` to `BVec4`
note: return type inferred to be `BVec4` here
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:4518:9
     |
4518 |         ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:4501:17
     |
4501 |       #[languages(on_feature(lua))]
     |                   ^^^^^^^^^^^^^^ expected `BVec4A`, found `BVec4`
...
4567 | /         ///Returns a vector mask containing the result of a `==` comparison for each element of
4568 | |         ///`self` and `rhs`.
4569 | |         ///
4570 | |         ///In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
4571 | |         ///elements.
4572 | |         cmpeq(self:self) -> Wrapped(BVec4A),
     | |__________________________________________- arguments to this function are incorrect
     |
note: associated function defined here
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/wrappers.rs:38:16
     |
38   |         pub fn new(b: $type_) -> Self {
     |                ^^^ ---------
     |
    ::: /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:5050:17
     |
5050 |     #[languages(on_feature(lua))]
     |                 -------------- in this macro invocation
     = note: this error originates in the macro `impl_lua_newtype` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:4501:17
     |
4501 |       #[languages(on_feature(lua))]
     |                   ^^^^^^^^^^^^^^ expected `BVec4A`, found `BVec4`
...
4574 | /         ///Returns a vector mask containing the result of a `!=` comparison for each element of
4575 | |         ///`self` and `rhs`.
4576 | |         ///
4577 | |         ///In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
4578 | |         ///elements.
4579 | |         cmpne(self:self) -> Wrapped(BVec4A),
     | |__________________________________________- arguments to this function are incorrect
     |
note: associated function defined here
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/wrappers.rs:38:16
     |
38   |         pub fn new(b: $type_) -> Self {
     |                ^^^ ---------
     |
    ::: /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:5050:17
     |
5050 |     #[languages(on_feature(lua))]
     |                 -------------- in this macro invocation
     = note: this error originates in the macro `impl_lua_newtype` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:4501:17
     |
4501 |       #[languages(on_feature(lua))]
     |                   ^^^^^^^^^^^^^^ expected `BVec4A`, found `BVec4`
...
4581 | /         ///Returns a vector mask containing the result of a `>=` comparison for each element of
4582 | |         ///`self` and `rhs`.
4583 | |         ///
4584 | |         ///In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
4585 | |         ///elements.
4586 | |         cmpge(self:self) -> Wrapped(BVec4A),
     | |__________________________________________- arguments to this function are incorrect
     |
note: associated function defined here
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/wrappers.rs:38:16
     |
38   |         pub fn new(b: $type_) -> Self {
     |                ^^^ ---------
     |
    ::: /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:5050:17
     |
5050 |     #[languages(on_feature(lua))]
     |                 -------------- in this macro invocation
     = note: this error originates in the macro `impl_lua_newtype` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:4501:17
     |
4501 |       #[languages(on_feature(lua))]
     |                   ^^^^^^^^^^^^^^ expected `BVec4A`, found `BVec4`
...
4588 | /         ///Returns a vector mask containing the result of a `>` comparison for each element of
4589 | |         ///`self` and `rhs`.
4590 | |         ///
4591 | |         ///In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all
4592 | |         ///elements.
4593 | |         cmpgt(self:self) -> Wrapped(BVec4A),
     | |__________________________________________- arguments to this function are incorrect
     |
note: associated function defined here
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/wrappers.rs:38:16
     |
38   |         pub fn new(b: $type_) -> Self {
     |                ^^^ ---------
     |
    ::: /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:5050:17
     |
5050 |     #[languages(on_feature(lua))]
     |                 -------------- in this macro invocation
     = note: this error originates in the macro `impl_lua_newtype` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:4501:17
     |
4501 |       #[languages(on_feature(lua))]
     |                   ^^^^^^^^^^^^^^ expected `BVec4A`, found `BVec4`
...
4595 | /         ///Returns a vector mask containing the result of a `<=` comparison for each element of
4596 | |         ///`self` and `rhs`.
4597 | |         ///
4598 | |         ///In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
4599 | |         ///elements.
4600 | |         cmple(self:self) -> Wrapped(BVec4A),
     | |__________________________________________- arguments to this function are incorrect
     |
note: associated function defined here
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/wrappers.rs:38:16
     |
38   |         pub fn new(b: $type_) -> Self {
     |                ^^^ ---------
     |
    ::: /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:5050:17
     |
5050 |     #[languages(on_feature(lua))]
     |                 -------------- in this macro invocation
     = note: this error originates in the macro `impl_lua_newtype` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:4501:17
     |
4501 |       #[languages(on_feature(lua))]
     |                   ^^^^^^^^^^^^^^ expected `BVec4A`, found `BVec4`
...
4602 | /         ///Returns a vector mask containing the result of a `<` comparison for each element of
4603 | |         ///`self` and `rhs`.
4604 | |         ///
4605 | |         ///In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
4606 | |         ///elements.
4607 | |         cmplt(self:self) -> Wrapped(BVec4A),
     | |__________________________________________- arguments to this function are incorrect
     |
note: associated function defined here
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/wrappers.rs:38:16
     |
38   |         pub fn new(b: $type_) -> Self {
     |                ^^^ ---------
     |
    ::: /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:5050:17
     |
5050 |     #[languages(on_feature(lua))]
     |                 -------------- in this macro invocation
     = note: this error originates in the macro `impl_lua_newtype` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:4501:17
     |
4501 |       #[languages(on_feature(lua))]
     |                   ^^^^^^^^^^^^^^ expected `BVec4A`, found `BVec4`
...
4635 | /         ///Performs `is_nan` on each element of self, returning a vector mask of the results.
4636 | |         ///
4637 | |         ///In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`.
4638 | |         is_nan_mask(self:) -> Wrapped(BVec4A),
     | |____________________________________________- arguments to this function are incorrect
     |
note: associated function defined here
    --> /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/wrappers.rs:38:16
     |
38   |         pub fn new(b: $type_) -> Self {
     |                ^^^ ---------
     |
    ::: /Users/andrew/.cargo/git/checkouts/bevy_mod_scripting-66f82db9d3a19d6f/7590248/bevy_script_api/src/generated.rs:5050:17
     |
5050 |     #[languages(on_feature(lua))]
     |                 -------------- in this macro invocation
     = note: this error originates in the macro `impl_lua_newtype` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0308`.
error: could not compile `bevy_script_api` (lib) due to 8 previous errors

The only example that I could get to work was the complex_game_loop one. All the others I tried (including the Game of Life) had the same problem

I'm currently on the stable branch but I also tried some examples with nightly and had the same problem as well

uhh, okay I think this might be something to do with platform differences, maybe BVec4 and BVec4A are aliases on your arch and the macro treats them differently. Which OS and arch are your using ?

I'm using an M2 (Arm) Mac so you may be right! If you give me pointers for where to start looking into this issue I can try to fix it later today

How do you regenerate bevy_script_api/src/generated.rs? It seems to require json files in target/doc, but I'm not sure where those come from.

generated.rs contains this section:

impl_script_newtype! {
    #[languages(on_feature(lua))]
    ///A 4-dimensional vector.
    ///
    ///SIMD vector types are used for storage on supported platforms.
    ///
    ///This type is 16 byte aligned.
    glam::f32::Vec4 :
    Clone +
    Debug +
    Methods
    (
        ///Creates a new vector.
        new(Raw(f32),Raw(f32),Raw(f32),Raw(f32)) -> self,

        ///Creates a vector with all elements set to `v`.
        splat(Raw(f32)) -> self,

        ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
        ///for each element of `self`.
        ///
        ///A true element in the mask uses the corresponding element from `if_true`, and false
        ///uses the element from `if_false`.
        select(Wrapped(BVec4A),self,self) -> self,

This is where the problem is. It's supposed to be an implementation for glam::f32::Vec4, but the generated function body uses BVec4A instead of BVec4

I found the makefile and generated the docs. I think I found the issue.

The glam-rs impl of Vec4 comparison functions return a BVec4A: https://github.com/bitshifter/glam-rs/blob/5fd61e965f777dc0e3c3d353e9007e5a7c957304/src/f32/coresimd/vec4.rs#L211

I'm not sure why this works for you though. It may have something to do with this: bitshifter/glam-rs#296

I tried re-generated the glam docs with the core-simd feature enabled and then re-generated generated.rs but the issue persists.

Changing the function signatures in generated.rs to return BVec4 instead of BVec4A fixes the build issue, but I don't know what will happen if we actually call those functions from Lua. I'll try tomorrow and report back

Hey @CyanBlob fantastic work! Sorry I didn't manage to give you pointers before you started!

Yup that will be it, glam generates a different interface completely for Vec4 depending on if simd is available.

At its root this will come from the fact codegen is executed on one machine (mine) and not at the end users machine. I suppose we don't necessarily have to do that, instead codegen should generate 'generated.rs' multiple times, once per architecture/feature that changes the interface and separate them by module, then hide this away with clever conditional imports. I haven't tried cross compiling in rust but hopefully it's not a pain to do.
Alternatively we could generate as a compile step but I would like to avoid increasing compilation times

We also need to modify the CI so this doesn't go unseen in the feature by adding an arch row to the feature matrix (if possible)!

Again thanks a lot for investigating @CyanBlob, if you're interested in writing a PR please feel free too, otherwise I'll take this on probably later tonight (UK time)

Actually maybe having the API vary based on arch is not as good a solution I thought, it could entail having to write platform dependent code on the script side which is.. yucky.

Maybe we need to manually override these functions to abstract away these differences, for example by returning the type which is available on all platforms. Although this will probably sacrifice some performance I think a clean and stable API is more important

Okay I finally found a way to replicate this using cross this appears on linux arm64 builds as well:

cross run --target=aarch64-unknown-linux-gnu --example bevy_api_lua --features=lua54,lua_script_api

This is now part of the CI, and so a complete fix will pass CI: https://github.com/makspll/bevy_mod_scripting/actions/runs/6473615465/job/17576720332

I've cross-compiled to aarch64-unknown-linux-gnu and generated a diff between the generated API files:

4470a4471,4473
>         x: Raw(f32),
>         y: Raw(f32),
>         z: Raw(f32),
4503,4506d4505
<     ///
<     ///SIMD vector types are used for storage on supported platforms.
<     ///
<     ///This type is 16 byte aligned.
4523c4522
<         select(Wrapped(BVec4A),self,self) -> self,
---
>         select(Wrapped(BVec4),self,self) -> self,
4572c4571
<         cmpeq(self:self) -> Wrapped(BVec4A),
---
>         cmpeq(self:self) -> Wrapped(BVec4),
4579c4578
<         cmpne(self:self) -> Wrapped(BVec4A),
---
>         cmpne(self:self) -> Wrapped(BVec4),
4586c4585
<         cmpge(self:self) -> Wrapped(BVec4A),
---
>         cmpge(self:self) -> Wrapped(BVec4),
4593c4592
<         cmpgt(self:self) -> Wrapped(BVec4A),
---
>         cmpgt(self:self) -> Wrapped(BVec4),
4600c4599
<         cmple(self:self) -> Wrapped(BVec4A),
---
>         cmple(self:self) -> Wrapped(BVec4),
4607c4606
<         cmplt(self:self) -> Wrapped(BVec4A),
---
>         cmplt(self:self) -> Wrapped(BVec4),
4638c4637
<         is_nan_mask(self:) -> Wrapped(BVec4A),
---
>         is_nan_mask(self:) -> Wrapped(BVec4),
4808a4808,4811
>         x: Raw(f32),
>         y: Raw(f32),
>         z: Raw(f32),
>         w: Raw(f32),
4999,5001c5002
<     ///A 3-dimensional SIMD vector mask.
<     ///
<     ///This type is 16 byte aligned.
---
>     ///A 3-dimensional `u32` vector mask.
5037a5039,5041
>         x: Raw(u32),
>         y: Raw(u32),
>         z: Raw(u32),
5051,5053c5055
<     ///A 4-dimensional SIMD vector mask.
<     ///
<     ///This type is 16 byte aligned.
---
>     ///A 4-dimensional `u32` vector mask.
5089a5092,5095
>         x: Raw(u32),
>         y: Raw(u32),
>         z: Raw(u32),
>         w: Raw(u32),
7384,7387d7389
<     ///
<     ///SIMD vector types are used for storage on supported platforms.
<     ///
<     ///This type is 16 byte aligned.
7478a7481,7482
>         x_axis: Wrapped(Vec2),
>         y_axis: Wrapped(Vec2),
9401,9404d9404
<     ///
<     ///SIMD vector types are used for storage on supported platforms.
<     ///
<     ///This type is 16 byte aligned.
9642a9643,9646
>         x: Raw(f32),
>         y: Raw(f32),
>         z: Raw(f32),
>         w: Raw(f32),

@CyanBlob could you try this branch? #80

This is fixed by #106