Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to define align for Packed based on Platform #48996

Open
aeb-dev opened this issue May 11, 2022 · 3 comments
Open

How to define align for Packed based on Platform #48996

aeb-dev opened this issue May 11, 2022 · 3 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi

Comments

@aeb-dev
Copy link

aeb-dev commented May 11, 2022

I have create a library for steam api. In steam, the alignment of structs changes from platform to platform. i.e. certain structs are aligned by 4 in linux and mac but 8 in windows.

I could not find a way to this in dart without writing two independent code per different configuration.

Here is an example:

import "dart:ffi";

const int align = 4;
@Packed(align)
class ActiveBeaconsUpdated extends Opaque {
}

The constant align should be able to change depending on the platform.

Now, I afaik, compiler directives are not implemented in dart so there is no way to do this in compile time.

There again afaik, the only way to do this is eliminate const from the constructor of the Packed.

If there is any workaround other that writing duplicate package per platform please let me know.

The steam api repo is here if you want to investigate further: https://github.com/aeb-dev/steamworks

@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi labels May 11, 2022
@mraleph
Copy link
Member

mraleph commented May 12, 2022

You should not need @Packed on an Opaque, maybe I am missing something. Did you mean to say extends Struct?

This might need either AbiSpecificInteger treatment or tie into introducing compile time constants to distinguish specific platforms.

/cc @dcharkes @mkustermann

@dcharkes
Copy link
Contributor

We indeed do not have support for different alignment of the same struct for different ABIs. We could implement that, it should be a fairly small change.

Implementing ABI-specific structs would be a more general solution. That is a bit more involved change, but it would solve this issue as well (and prevent us from having two ways to solve this issue).

@aeb-dev
Copy link
Author

aeb-dev commented May 12, 2022

You should not need @PACKED on an Opaque, maybe I am missing something. Did you mean to say extends Struct?

I have no idea. Steam has different alignment for the same struct but the struct is empty on steam as well.

@dcharkes I checked the issue you have linked and I like the idea. Does it have any planned release date?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi
Projects
None yet
Development

No branches or pull requests

4 participants