Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/jnigen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel: true
path-to-lcov: ./pkgs/jni/coverage/lcov.info
# TODO(https://github.com/dart-lang/ffigen/issues/555): Ffigen generated
# TODO(https://github.com/dart-lang/ffigen/issues/555): FFIgen generated
# on my machine has macOS specific stuff and CI does not.
# We should just generate the struct as opaque, but we currently can't.
#
Expand Down
20 changes: 10 additions & 10 deletions pkgs/ffigen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
[a bug](https://github.com/dart-lang/http/issues/1702), by removing all uses
of `NSProxy`.
- __Breaking change__: Change how duplicate identifiers are renamed to match
jnigen. The main change is that `$` is used as a delimiter now, to avoid
JNIgen. The main change is that `$` is used as a delimiter now, to avoid
renamed identifiers from colliding with other identifiers. For example, `foo`
is renamed to `foo$1` if there's already a `foo` in the namespace.
- Fix [a bug](https://github.com/dart-lang/native/issues/1967) where blocking
Expand Down Expand Up @@ -178,7 +178,7 @@

## 14.0.0

- Create a public facing API for ffigen that can be invoked as a library:
- Create a public facing API for FFIgen that can be invoked as a library:
`void generate(Config config)`. Make `Config` an implementatble interface,
rather than needing to be parsed from yaml.
- Add a `external-versions` config option. Setting the minimum target
Expand All @@ -194,7 +194,7 @@
- __Breaking change__: Generated ObjC code has been migrated to ARC (Automatic
Reference Counting), and must now be compiled with ARC enabled. For example,
if you had a line like `s.requires_arc = []` in your podspec, this should
either be removed, or you should add the ffigen generated ObjC code to the
either be removed, or you should add the FFIgen generated ObjC code to the
list. If you're compiling directly with clang, add the `-fobjc-arc` flag.
- __Breaking change__: Structs with enum members now generate their members
as Dart enum values as well. For example, with an enum `MyEnum` and a struct
Expand Down Expand Up @@ -258,11 +258,11 @@
https://github.com/dart-lang/native/issues/1068 is fixed).
- Core classes such as `NSString` have been moved into `package:objective_c`.
- ObjC class methods don't need the ubiquitous `lib` argument anymore. In
fact, ffigen won't even generate the native library class (unless it needs
fact, FFIgen won't even generate the native library class (unless it needs
to bind top level functions without using `@Native`). It is still necessary
to `DynamicLibrary.open` the dylib though, to load the classes and methods.
- Adapting to this change:
- Update ffigen and re-run the code generation. If the generated code no
- Update FFIgen and re-run the code generation. If the generated code no
longer contains the native library class, it means it isn't needed
anymore. So `final lib = FooNativeLib(DynamicLibrary.open('foo.dylib'));`
must be changed to `DynamicLibrary.open('foo.dylib');`.
Expand All @@ -272,7 +272,7 @@
- If core ObjC classes such as `NSString` are being used,
`package:objective_c` must be imported, as they won't be exported by the
generated bindings.
- Add --[no-]format option to ffigen command line, which controls whether the
- Add --[no-]format option to FFIgen command line, which controls whether the
formatting step happens. Defaults to true.
- Delete Dart functions associated with ObjC closure blocks when the block is
destroyed. Fixes https://github.com/dart-lang/native/issues/204
Expand Down Expand Up @@ -412,7 +412,7 @@ and examples/shared_bindings).

## 7.0.0-dev

- Relative paths in ffigen config files are now assumed to be relative to the
- Relative paths in FFIgen config files are now assumed to be relative to the
config file, rather than the working directory of the tool invocation.

## 6.1.2
Expand Down Expand Up @@ -569,7 +569,7 @@ automatically but can be overriden using `structs -> pack` config.

## 2.2.3
- Added new subkey `dependency-only` (options - `full (default) | opaque`) under `structs`.
When set to `opaque`, ffigen will generate empty `Opaque` structs if structs
When set to `opaque`, FFIgen will generate empty `Opaque` structs if structs
were excluded in config (i.e added because they were a dependency) and
only passed by reference(pointer).

Expand Down Expand Up @@ -613,7 +613,7 @@ structs having `Opaque` members.
- Removed the usage of `--no-sound-null-safety` flag.

## 2.0.0-dev.2
- Removed setup phase for ffigen. Added new optional config key `llvm-lib`
- Removed setup phase for FFIgen. Added new optional config key `llvm-lib`
to specify path to `llvm/lib` folder.

## 2.0.0-dev.1
Expand Down Expand Up @@ -668,7 +668,7 @@ to specify path to `llvm/lib` folder.
- Added config `dart-bool` (default: true) to use dart bool instead of int in function parameters and return type.

## 0.2.3+3
- Wrapper dynamic library version now uses ffigen version from its pubspec.yaml file.
- Wrapper dynamic library version now uses FFIgen version from its pubspec.yaml file.

## 0.2.3+2
- Handle code formatting using dartfmt by finding dart-sdk.
Expand Down
6 changes: 3 additions & 3 deletions pkgs/ffigen/doc/errors.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Errors in ffigen
# Errors in FFIgen

This file documents various errors and their potential fixes related to ffigen.
This file documents various errors and their potential fixes related to FFIgen.

## Errors in source header files

Expand Down Expand Up @@ -43,7 +43,7 @@ Since Dart doesn't support method overloading, the method may have been renamed
to avoid collisions. Again the best approach is to search for the ObjC method
name.

When ffigen generates bindings for an ObjC interface, eg `Foo`, it generates a
When FFIgen generates bindings for an ObjC interface, eg `Foo`, it generates a
Dart class `Foo`, which contains the constructor and static methods. The
instance methods are generated in an extension, `Foo$Methods`.

Expand Down
8 changes: 4 additions & 4 deletions pkgs/ffigen/example/objective_c/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Objective C example

This example shows how to use ffigen to generate bindings for an Objective C
This example shows how to use FFIgen to generate bindings for an Objective C
library. It uses the AVFAudio framework to play audio files.

```
Expand All @@ -9,13 +9,13 @@ dart play_audio.dart test.mp3

## Config notes

The ffigen config for an Objective C library looks very similar to a C library.
The FFIgen config for an Objective C library looks very similar to a C library.
The most important difference is that you must set `language: objc`. If you want
to filter which interfaces are included you can use the `objc-interfaces:`
option. This works similarly to the other filtering options.

It is recommended that you filter out just about everything you're not
interested in binding (see the ffigen config in [pubspec.yaml](./pubspec.yaml)).
interested in binding (see the FFIgen config in [pubspec.yaml](./pubspec.yaml)).
Virtually all Objective C libraries depend on Apple's internal libraries, which
are huge. Filtering can reduce the generated bindings from millions of lines to
tens of thousands. You can use the `exclude-all-by-default` flag, or exclude
Expand All @@ -29,7 +29,7 @@ functions:
```

In this example, we're only interested in `AVAudioPlayer`, so we've filtered out
everything else. But ffigen will automatically pull in anything referenced by
everything else. But FFIgen will automatically pull in anything referenced by
any of the fields or methods of `AVAudioPlayer`, so we're still able to use
`NSURL` etc to load our audio file.

Expand Down
10 changes: 5 additions & 5 deletions pkgs/ffigen/example/swift/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Swift example

This example shows how to use ffigen to interact with Swift libraries.
This example shows how to use FFIgen to interact with Swift libraries.

Swift APIs can be made compatible with Objective-C, using the `@objc`
annotation. Then you can use the `swiftc` tool to build a dylib for the library
Expand All @@ -18,15 +18,15 @@ This should generate libswiftapi.dylib and swift_api.h.
For more information about Objective-C / Swift interoperability, see the
[Apple documentation](https://developer.apple.com/documentation/swift/importing-swift-into-objective-c).

Once you have an Objective-C wrapper header, ffigen can parse it like
Once you have an Objective-C wrapper header, FFIgen can parse it like
any other header:

```shell
dart run ffigen --config config.yaml
```

This will generate [swift_api_bindings.dart](./swift_api_bindings.dart),
using the config in the ffigen section of the pubspec.yaml.
using the config in the FFIgen section of the pubspec.yaml.

Finally, you can run the example using this command:

Expand All @@ -36,7 +36,7 @@ dart run example.dart

## Config notes

Ffigen only sees the Objective-C wrapper header, swift_api.h. So you
FFIgen only sees the Objective-C wrapper header, swift_api.h. So you
need to set the language to objc, and set the entry-point to the header:

```yaml
Expand All @@ -57,7 +57,7 @@ objc-interfaces:
There is one extra option you need to set when wrapping a Swift library.
When `swiftc` compiles the library, it gives the Objective-C interface
a module prefix. Internally, our `SwiftClass` is actually registered
as `swift_module.SwiftClass`. So you need to tell ffigen about this prefix,
as `swift_module.SwiftClass`. So you need to tell FFIgen about this prefix,
so it loads the correct class from the dylib:

```yaml
Expand Down
5 changes: 4 additions & 1 deletion pkgs/ffigen/lib/ffigen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
// 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.

/// This is the Dart API for ffigen. The main entrypoint is the FfiGen class.
/// This is the Dart API for FFIgen. The main entrypoint is the [FfiGenerator]
/// class.
///
/// For most use cases the YAML based API is simpler. See
/// https://pub.dev/packages/ffigen for details.
///
/// {@category Errors}
///
/// @docImport 'src/config_provider.dart';
library;

export 'src/code_generator/imports.dart' show ImportedType, LibraryImport;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ffigen/lib/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This is the main entry point for the user- `dart run ffigen`.
- `--verbose`: Sets log level.
- `--config`: Specifies a config file.
- The internal modules are called by `ffigen.dart` in the following way:
- `ffigen.dart` will try to find dynamic library in default locations. If that fails, the user must excplicitly specify location in ffigen's config under the key `llvm-path`.
- `ffigen.dart` will try to find dynamic library in default locations. If that fails, the user must excplicitly specify location in FFIgen's config under the key `llvm-path`.
- It first creates a `Config` object from an input Yaml file. This is used by other modules.
- The `parse` method is then invoked to generate a `Library` object.
- Finally, the code is generated from the `Library` object to the specified file.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ffigen/lib/src/code_generator/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Scope {
/// This is meant to be used during code generation, for generating unique
/// names for internal use only. It shouldn't be used for user visible names,
/// or for names that need to be used in multiple disparate places throughout
/// ffigen. If you're storing the name in a long term variable, you should
/// FFIgen. If you're storing the name in a long term variable, you should
/// probably be using a proper [Symbol].
///
/// To help ensure correct use, only names beginning with '_' are allowed.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ffigen/lib/src/config_provider/yaml_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class YamlConfig {
SymbolFile? get symbolFile => _symbolFile;
late SymbolFile? _symbolFile;

/// Language that ffigen is consuming.
/// Language that FFIgen is consuming.
Language get language => _language;
late Language _language;

Expand Down
4 changes: 2 additions & 2 deletions pkgs/ffigen/lib/src/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'config_provider/spec_utils.dart';
import 'header_parser/clang_bindings/clang_bindings.dart' show Clang;
import 'header_parser/utils.dart';

/// Wrapper around various ffigen-wide variables.
/// Wrapper around various FFIgen-wide variables.
class Context {
final Logger logger;
final Config config;
Expand Down Expand Up @@ -53,7 +53,7 @@ class Context {
//
// Ideally this would be in the Context, but the plumbing needed would be
// excessive. The point of putting globals in the Context is to allow multiple
// concurrent FfiGen runs without any risk of clobbering global state. The
// concurrent FFIgen runs without any risk of clobbering global state. The
// clang bindings are loaded from a dylib specified by the config, so it's
// possible that two different versions of clang could be loaded. But since we
// interact with clang through a stable API, there's no real danger of version
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ffigen/test/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ffigen testing
# FFIgen testing

## Running Tests

Expand Down
4 changes: 2 additions & 2 deletions pkgs/ffigen/test/native_objc_test/setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ List<String> _getTestNames() {
}

Future<void> build(List<String> testNames) async {
// Swift build comes first because the generated header is consumed by ffigen.
// Swift build comes first because the generated header is consumed by FFIgen.
print('Building Dynamic Library and Header for Swift Tests...');
for (final name in testNames) {
final swiftFile = '${name}_test.swift';
Expand All @@ -124,7 +124,7 @@ Future<void> build(List<String> testNames) async {
}
}

// Ffigen comes next because it may generate an ObjC file that is compiled
// FFIgen comes next because it may generate an ObjC file that is compiled
// into the dylib.
print('Generating Bindings for Objective C Native Tests...');
for (final name in testNames) {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ffigen/test/native_objc_test/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import '../test_utils.dart';

void generateBindingsForCoverage(String testName, [Logger? logger]) {
// The ObjC test bindings are generated in setup.dart (see #362), which means
// that the ObjC related bits of ffigen are missed by test coverage. So this
// that the ObjC related bits of FFIgen are missed by test coverage. So this
// function just regenerates those bindings. It doesn't test anything except
// that the generation succeeded, by asserting the file exists.
final path = p.join(
Expand Down
8 changes: 4 additions & 4 deletions pkgs/jni/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
[![pub package](https://img.shields.io/pub/v/jni.svg)](https://pub.dev/packages/jni)
[![package publisher](https://img.shields.io/pub/publisher/jni.svg)](https://pub.dev/packages/jni/publisher)

# jni
# JNI

This is a support library to access JNI from Dart / Flutter code. This provides the common infrastructure to bindings generated by [jnigen](https://pub.dev/packages/jnigen), as well as some utility methods.
This is a support library to access JNI from Dart / Flutter code. This provides the common infrastructure to bindings generated by [JNIgen](https://pub.dev/packages/jnigen), as well as some utility methods.

This library contains:

* Functions to access the JNIEnv and JavaVM variables from JNI, and wrapper functions to those provided by JNI. JNIEnv is exposed via `GlobalJniEnv` type which provides a thin abstraction over JNIEnv, so that it can be used from multiple threads.
* Functions to spawn a JVM on desktop platforms (`Jni.spawn`).
* Some Android-specific helpers (get application context and current activity references).
* `JObject` class, which provides base class for classes generated by jnigen.
* `JObject` class, which provides base class for classes generated by JNIgen.
* Commonly used Java classes like `JList`, `JMap`, `JInteger`, ...

Apart from being the base library for code generated by `jnigen` this can also be used for one-off uses of the JNI and debugging. __To generate type-safe bindings from Java libraries, use `jnigen`.__
Apart from being the base library for code generated by JNIgen this can also be used for one-off uses of the JNI and debugging. __To generate type-safe bindings from Java libraries, use JNIgen.__

## Documentation
The test/ directory contains files with comments explaining the basics of this module, and the example/ directory contains a flutter example which also touches some Android-specifics.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/jni/ffigen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ functions:
- 'GetJniContextPtr'
- 'setJniGetters'
- 'jni_log'
# Exclude functions with VarArgs, jnigen will generate them based on the
# Exclude functions with VarArgs, JNIgen will generate them based on the
# exact arguments needed.
- 'globalEnv_NewObject'
- 'globalEnv_Call(Static|Nonvirtual|)[A-Z][a-z]+Method'
Expand Down
6 changes: 3 additions & 3 deletions pkgs/jni/lib/jni.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// Package jni provides dart bindings for the Java Native Interface (JNI) on
/// Android and desktop platforms.
///
/// It's intended as a supplement to the jnigen tool, a Java wrapper generator
/// It's intended as a supplement to the JNIgen tool, a Java wrapper generator
/// using JNI. The goal of this package is to provide sufficiently complete
/// and ergonomic access to underlying JNI APIs.
///
Expand All @@ -31,8 +31,8 @@
/// standalone:
///
/// * Run `dart run jni:setup` to build the shared library. This command builds
/// all dependency libraries with native code (package:jni and jnigen-generated)
/// libraries if any.
/// all dependency libraries with native code (package:jni and JNIgen-generated
/// libraries if any).
///
/// The default output directory is build/jni_libs, which can be changed
/// using `-B` switch.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/jni/lib/src/jni.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ abstract final class Jni {
JGlobalReference(_bindings.GetClassLoader());
}

/// Extensions for use by `jnigen` generated code.
/// Extensions for use by JNIgen generated code.
@internal
extension ProtectedJniExtensions on Jni {
static bool _initialized = false;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/jni/lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mixin JAccessible<JavaT, DartT> on JTypeBase<JavaT> {
void _instanceSet(JObjectPtr obj, JFieldIDPtr fieldID, DartT val);
}

/// Only used for jnigen.
/// Only used for JNIgen.
///
/// Makes constructing objects easier inside the generated bindings by allowing
/// a [JReference] to be created. This allows [JObject]s to use constructors
Expand Down
2 changes: 1 addition & 1 deletion pkgs/jni/test/jobject_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void run({required TestRunnerCallback testRunner}) {
// And thus can be too verbose for simple experimenting and one-off uses
// JClass API provides an easier way to perform some common operations.
//
// However, if binding generation using jnigen is possible, that should be
// However, if binding generation using JNIgen is possible, that should be
// the first choice.
testRunner('Long.intValue() using JClass', () {
// JClass wraps a local class reference, and
Expand Down
4 changes: 2 additions & 2 deletions pkgs/jni/tool/generate_ffi_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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.

// This script generates all FFIGEN-based bindings we require to use JNI, which
// This script generates all FFIgen-based bindings we require to use JNI, which
// includes some C wrappers over `JNIEnv` type and some Dart extension methods.

import 'dart:io';
Expand All @@ -25,7 +25,7 @@ void main(List<String> args) {
..addOption(
'verbose',
defaultsTo: 'severe',
help: 'set ffigen log verbosity',
help: 'set FFIgen log verbosity',
allowed: levels.keys,
)
..addFlag(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool hasVarArgs(String name) {
RegExp(r'^Call(Static|Nonvirtual|)[A-Z][a-z]+Method$').hasMatch(name);
}

/// Get C name of a type from its ffigen representation.
/// Get C name of a type from its FFIgen representation.
String getCType(Type type) {
if (type is PointerType) {
return '${getCType(type.child)}*';
Expand Down
Loading
Loading