Skip to content

Posix bindings #2292

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pkgs/hooks/example/build/native_add_library/constants-ffigen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Run with `flutter pub run ffigen --config ffigen.yaml`.
name: NativeAddBindings
description: |
Bindings for `src/native_add_library.h`.

Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`.
output: 'lib/src/constant_bindings.dart'
headers:
entry-points:
- 'src/constants.g.h'

include-directives:
- 'src/constants.g.h'
preamble: |
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
comments:
style: any
length: full
ffi-native:

structs:
rename:
'my_(.*)': '$1'
functions:
rename:
'my_(.*)': '$1'
typedefs:
rename:
'my_(.*)': '$1'
32 changes: 32 additions & 0 deletions pkgs/hooks/example/build/native_add_library/constants.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
"S_IEXEC",
"S_IFBLK",
"S_IFCHR",
"S_IFDIR",
"S_IFIFO",
"S_IFLNK",
"S_IFMT",
"S_IFREG",
"S_IFSOCK",
"S_IFWHT",
"S_IREAD",
"S_IRGRP",
"S_IROTH",
"S_IRUSR",
"S_IRWXG",
"S_IRWXO",
"S_IRWXU",
"S_ISGID",
"S_ISTXT",
"S_ISUID",
"S_ISVTX",
"S_IWGRP",
"S_IWOTH",
"S_IWRITE",
"S_IWUSR",
"S_IXGRP",
"S_IXOTH",
"S_IXUSR",
"UF_APPEND",
"UF_HIDDEN"
]
13 changes: 12 additions & 1 deletion pkgs/hooks/example/build/native_add_library/ffigen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ description: |
Bindings for `src/native_add_library.h`.

Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`.
output: 'lib/native_add_library.dart'
output: 'lib/src/libc_bindings.dart'
headers:
entry-points:
- 'src/native_add_library.h'

include-directives:
- 'src/native_add_library.h'
preamble: |
Expand All @@ -18,3 +19,13 @@ comments:
style: any
length: full
ffi-native:

structs:
rename:
'my_(.*)': '$1'
functions:
rename:
'my_(.*)': '$1'
typedefs:
rename:
'my_(.*)': '$1'
5 changes: 3 additions & 2 deletions pkgs/hooks/example/build/native_add_library/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ void main(List<String> args) async {
final packageName = input.packageName;
final cbuilder = CBuilder.library(
name: packageName,
assetName: '$packageName.dart',
sources: ['src/$packageName.c'],
assetName: 'src/libc_bindings.dart',
sources: ['src/$packageName.c', 'src/constants.g.c'],
flags: ['-Weverything'],
);
await cbuilder.run(
input: input,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'src/libc_bindings.dart' as libc;

// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
// ignore_for_file: type=lint
import 'dart:ffi' as ffi;
export 'src/constants.g.dart';
export 'src/libc_bindings.dart' hide errno, seterrno;

@ffi.Native<ffi.Int32 Function(ffi.Int32, ffi.Int32)>()
external int add(int a, int b);
int get errno => libc.errno();
set errno(int err) => libc.seterrno(err);
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
// ignore_for_file: type=lint
import 'dart:ffi' as ffi;

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IEXEC')
external int get_S_IEXEC();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IFBLK')
external int get_S_IFBLK();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IFCHR')
external int get_S_IFCHR();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IFDIR')
external int get_S_IFDIR();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IFIFO')
external int get_S_IFIFO();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IFLNK')
external int get_S_IFLNK();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IFMT')
external int get_S_IFMT();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IFREG')
external int get_S_IFREG();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IFSOCK')
external int get_S_IFSOCK();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IFWHT')
external int get_S_IFWHT();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IREAD')
external int get_S_IREAD();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IRGRP')
external int get_S_IRGRP();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IROTH')
external int get_S_IROTH();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IRUSR')
external int get_S_IRUSR();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IRWXG')
external int get_S_IRWXG();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IRWXO')
external int get_S_IRWXO();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IRWXU')
external int get_S_IRWXU();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_ISGID')
external int get_S_ISGID();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_ISTXT')
external int get_S_ISTXT();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_ISUID')
external int get_S_ISUID();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_ISVTX')
external int get_S_ISVTX();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IWGRP')
external int get_S_IWGRP();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IWOTH')
external int get_S_IWOTH();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IWRITE')
external int get_S_IWRITE();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IWUSR')
external int get_S_IWUSR();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IXGRP')
external int get_S_IXGRP();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IXOTH')
external int get_S_IXOTH();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_S_IXUSR')
external int get_S_IXUSR();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_UF_APPEND')
external int get_UF_APPEND();

@ffi.Native<ffi.Int64 Function()>(symbol: 'my_get_UF_HIDDEN')
external int get_UF_HIDDEN();

const int my_UNDEFINED = 9223372036854775807;
Loading
Loading