Skip to content

[ffigen] Generate assert or comment about the package:objective_c version #2807

@liamappelbe

Description

@liamappelbe

FFIgen and objective_c are pretty tightly coupled. It might make sense to code gen a comment or assert about the version of package:objective_c that the generated code expects.

// WARNING: This generated code uses package:objective_c v9.2.0
import 'package:objective_c/objective_c.dart' as objc;

void _versionCheck() {  // We'd need to call this somewhere in the bindings. Maybe when loading class objects?
  assert(objc.version.major == 9 && objc.version.minor >= 2); 
}

A more out-there approach would be something like this, which enforces the tight coupling at compile time:

// In FFIgen's generated code... 

import 'package:objective_c/objective_c.dart' as objc;

const _requireObjectiveCVersion = objc.version_9_2_0;

To enforce that the major versions are equal, and that package:objective_c's minor version is greater than or equal to the one in the generated code, package:objective_c would define these version getters for each minor version in the current major version:

const bool version_9_0_0 = true;
const bool version_9_1_0 = true;
const bool version_9_2_0 = true;
const bool version_9_3_0 = true;

We'd probably want to codegen these, and have a test to make sure they're in sync with the pubspec version.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions