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

[vm/ffi] Platform.isX64 function #45254

Closed
Sunbreak opened this issue Mar 9, 2021 · 4 comments
Closed

[vm/ffi] Platform.isX64 function #45254

Sunbreak opened this issue Mar 9, 2021 · 4 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-ffi type-enhancement A request for a change that isn't a bug

Comments

@Sunbreak
Copy link

Sunbreak commented Mar 9, 2021

I'm working on https://github.com/woodemi/twaindsm.dart, and many scanner devices have only 32-bit driver

Could we have Platform.isX64 function, something like Platform.isWindows or kIsWeb, to determine coresponding 32-bit or 64-bit TWAINDSM.dll?

import 'dart:ffi';

const bool kIsX64 = sizeOf<Pointer>() == 8;
@lrhn lrhn added library-ffi type-enhancement A request for a change that isn't a bug labels Mar 9, 2021
@lrhn
Copy link
Member

lrhn commented Mar 9, 2021

Sounds like something which should be in the ffi libraries. (Also it should probably be related to the pointer size, not the underlying CPU architecture, so it works for ARM64 too.)
Would you need to distinguish x32 from x86 too?

@Sunbreak
Copy link
Author

Sunbreak commented Mar 9, 2021

Sounds like something which should be in the ffi libraries. (Also it should probably be related to the pointer size, not the underlying CPU architecture, so it works for ARM64 too.)
Would you need to distinguish x32 from x86 too?

ffi would be fine. No need for x32 for now :)

@srawlins srawlins added the area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. label Mar 9, 2021
@dcharkes
Copy link
Contributor

We only want to add things to dart:ffi which cannot be built on top of dart:ffi.

const bool kIsX64 = sizeOf<Pointer>() == 8; could go into package:ffi.

@Sunbreak could you make a PR?

Something like ffi/lib/src/platform.dart:

/// Whether Dart is running in 32-bit mode.
final bool is32Bit = sizeOf<Pointer>() == 4;

/// Whether Dart is running in 64-bit mode.
final bool is64Bit = sizeOf<Pointer>() == 8;

@lrhn would you be so kind to suggest a nice API? 😄

@Sunbreak note that you're not actually detecting the host OS, you're detecting whether Dart is running in 64-bit mode. You can execute a 32-bit Dart SDK on 64 bit Windows, but you'll not be able to load any 64-bit DLLs.

@Sunbreak
Copy link
Author

@Sunbreak note that you're not actually detecting the host OS, you're detecting whether Dart is running in 64-bit mode. You can execute a 32-bit Dart SDK on 64 bit Windows, but you'll not be able to load any 64-bit DLLs.

Yep. That's what I want to do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-ffi type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants