dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
83 stars 27 forks source link

Unsound Null-Safety #375

Closed mannprerak2 closed 3 years ago

mannprerak2 commented 3 years ago

We currently do not support sound null safety (added by dart-lang/ffigen#122).

Tasks Remaining:

TimWhiting commented 3 years ago

I'm having issues trying to do this.

$ dart --no-sound-null-safety pub global activate ffigen 2.0.0-dev.2
Package ffigen is currently active at version 1.2.0.
Resolving dependencies... (1.7s)
+ args 1.6.0
+ async 2.4.2
+ charcode 1.2.0-nullsafety.3
+ cli_util 0.2.0
+ collection 1.15.0-nullsafety.5
+ ffi 0.2.0-nullsafety.1
+ ffigen 2.0.0-dev.2 (2.0.0-nullsafety.0 available)
+ file 5.2.1
+ glob 1.2.0
+ intl 0.16.1
+ js 0.6.2
+ logging 0.11.4
+ matcher 0.12.10-nullsafety.3
+ meta 1.3.0-nullsafety.6
+ node_interop 1.2.1
+ node_io 1.2.0
+ path 1.8.0-nullsafety.3
+ pedantic 1.9.2
+ pub_semver 1.4.4
+ quiver 3.0.0-nullsafety.2
+ source_span 1.8.0-nullsafety.4
+ stack_trace 1.10.0-nullsafety.6
+ string_scanner 1.1.0-nullsafety.3
+ term_glyph 1.2.0-nullsafety.3
+ yaml 3.0.0-nullsafety.0
Precompiling executables... (1.0s)
Failed to precompile ffigen:ffigen:
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:args
 - package:cli_util
 - package:logging
 - package:pub_semver
 - package:glob
 - package:async
 - package:pedantic

For solutions, see https://dart.dev/go/unsound-null-safety

By having the correct version in dev dependencies and running it in the project I get a similar thing:

$ dart --no-sound-null-safety run ffigen
Precompiling executable... (1.1s)
Failed to precompile ffigen:ffigen:
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:args
 - package:cli_util
 - package:logging
 - package:pub_semver
 - package:glob
 - package:async
 - package:pedantic

For solutions, see https://dart.dev/go/unsound-null-safety
Failed to precompile ffigen:ffigen:
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:args
 - package:cli_util
 - package:logging
 - package:pub_semver
 - package:glob
 - package:async
 - package:pedantic

For solutions, see https://dart.dev/go/unsound-null-safety

dart --version Dart SDK version: 2.12.0-198.0.dev (dev) (Unknown timestamp) on "linux_x64"

Not sure if this is an issue with the SDK or this package. Seems odd, since I'm passing in a correct flag and it doesn't complain about the flag.

mannprerak2 commented 3 years ago

You need to run it like this -

dart --no-sound-null-safety run ffigen

Edit- I think this could be because you used pub to activate it globally? you shouldn't do that, so maybe try deactivating it first.

simc commented 3 years ago

@mannprerak2 I also don't get it to work. I don't have ffigen activated globally. I get the same error as @TimWhiting. I use the Dart SDK shipped with Flutter master (2.12.0-204.0.dev)

TimWhiting commented 3 years ago

Yep, still not working after deactivating globally. I'm guessing it somehow is related to dart plumbing the flag through precompiling executables that are not part of the current project.

TimWhiting commented 3 years ago

Workaround for now is to copy the ffigen.dart script from bin/ffigen.dart to the bin folder in the project you want to use it in. Then the ---no-sound-null-safety flag works. I wonder if you could just opt out that script from null-safety so that we don't have to use the workaround?

mannprerak2 commented 3 years ago

This seems to be an issue with dart, the --no-sound-null-safety flag doesn't sem to make any difference to precompiling packages.

We can follow in the steps of package:test (since it also runs without sound null safety). We need to add this comment //@dart=2.7 to our ffigen script so that it can be precompiled without the user even having to specify a flag. See https://github.com/dart-lang/test/blob/master/pkgs/test/bin/test.dart.

mannprerak2 commented 3 years ago

@leisim @TimWhiting We'll be releasing a new version to fix this soon, until then feel free to add a git dependency to get this to work.

for Dev channel -

ffigen:
    git:
      url: https://github.com/mannprerak2/ffigen.git
      ref: dev-remove-no-sound-null-safety-flag

for Beta channel -

ffigen:
    git:
      url: https://github.com/mannprerak2/ffigen.git
      ref: remove-no-sound-null-safety-flag
simc commented 3 years ago

@mannprerak2 Thanks for the fast fix. I tried both new versions from pub.dev but I always get this error:

[SEVERE] : Couldn't find an entry for 'ffigen' in pubspec.yaml.

When I switch back to the old version, I get the old error again.

mannprerak2 commented 3 years ago

Yes, you need to provide the configurations to the tool. See this -> https://github.com/dart-lang/ffigen#configurations

If you provide them via your pubspec.yaml file, then create a top level key ffigen in that file and add your configurations to that. Check out this example.

simc commented 3 years ago

@mannprerak2 Stupid mistake. Thanks a lot it works perfectly :+1:

maks commented 3 years ago

@mannprerak2 sorry I'm bit confused. I'm trying to use the new release 2.0.0-dev.0 to make use of the brand new support for nested structures but if I do so with a pubpsec of:

name: ffigen_sandbox
description: A simple command-line application.
# version: 1.0.0
# homepage: https://www.example.com

environment:
  sdk: ">=2.12.0-223.0.dev <3.0.0"

dev_dependencies:
  ffigen: 2.0.0-dev.0

ffigen:
  output: "generated_bindings.dart"
  headers:
    entry-points:
      - "fuse.h"
  array-workaround: true

and then try to run ffigen I get:

pub run ffigen
Precompiling executable... (1.9s)
Failed to precompile ffigen:ffigen:
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:args
 - package:cli_util
 - package:logging
 - package:pub_semver
 - package:glob
 - package:async
 - package:pedantic

For solutions, see https://dart.dev/go/unsound-null-safety

And I'm using:

dart --version
Dart SDK version: 2.12.0-223.0.dev (dev) (Wed Jan 13 03:24:39 2021 -0800) on "linux_x64"

So not sure what I'm doing wrong?

mannprerak2 commented 3 years ago

Hi @maks please use the latest dev version 2.0.0-dev.4. This will resolve the error.

maks commented 3 years ago

Thanks @mannprerak2 that got me past the null safety errors but now I get:

pub run ffigen
Precompiling executable... (3.5s)
Precompiled ffigen:ffigen.
Running in Directory: '/home/maks/work/dart_fuse'
[WARNING]: Prefer adding Key 'name' to your config.
[WARNING]: Prefer adding Key 'description' to your config.
[SEVERE] : Couldn't find dynamic library in default locations.
[SEVERE] : Please supply the path/to/llvm/lib in ffigen's config under the key 'llvm-lib'.
Unhandled exception:
Exception: Couldn't find dynamic library in default locations.
#0      findDylibAtDefaultLocations (package:ffigen/src/config_provider/spec_utils.dart:226:3)
dart-lang/ffigen#1      Config._getSpecs.<anonymous closure> (package:ffigen/src/config_provider/config.dart:171:29)
dart-lang/ffigen#2      Config._extract (package:ffigen/src/config_provider/config.dart:157:50)
dart-lang/ffigen#3      new Config.fromYaml (package:ffigen/src/config_provider/config.dart:120:17)
dart-lang/ffigen#4      getConfigFromPubspec (package:ffigen/src/executables/ffigen.dart:84:17)
dart-lang/ffigen#5      getConfig (package:ffigen/src/executables/ffigen.dart:57:12)
dart-lang/ffigen#6      main (package:ffigen/src/executables/ffigen.dart:35:14)
dart-lang/ffigen#7      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:281:32)
dart-lang/ffigen#8      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

If I change back to just the stable published version putting just ffigen: in pubspec it works again, but of course without nested structs support.

mannprerak2 commented 3 years ago

@maks you need to add the location to where llvm has been installed. E.g - llvm-lib: /usr/local/opt/llvm/lib. This location contains the required dynamic library (libclang.so/.dylib/.dll).

maks commented 3 years ago

Brill thanks @mannprerak2 that worked! I guess that's a new setting that was added so I didn't need it when I was using the older release.

mannprerak2 commented 3 years ago

Closed via dart-lang/ffigen#148.