Skip to content

[native-assets] Windows lookup fails when exe is symlinked #55207

@dnys1

Description

@dnys1

From the native_add_app example, run the following:

$ dart --enable-experiment=native-assets build .\bin\native_add_app.dart
$ .\bin\native_add_app\native_add_app.exe
Invoking a native function to calculate 1 + 2.
Invocation success: 1 + 2 = 3.

All good.

Now, create a symlink for the exe and run that:

$ New-Item -Path .\native_add_app.exe -ItemType SymbolicLink -Value .\bin\native_add_app\native_add_app.exe
$ .\native_add_app.exe
Invoking a native function to calculate 1 + 2.
Unhandled exception:
Invalid argument(s): Couldn't resolve native function 'add' in 'package:native_add_library/native_add_library.dart' : Failed to load dynamic library 'native_add_library.dll': Failed to load dynamic library 'c:/workspace/native/pkgs/native_assets_cli/example/native_add_app/native_add_library.dll': The specified module could not be found.
 (error code: 126).

#0      Native._ffi_resolver.#ffiClosure0 (dart:ffi-patch/ffi_patch.dart)
dart-lang/native#1      Native._ffi_resolver_function (dart:ffi-patch/ffi_patch.dart:1386)
dart-lang/native#2      add (package:native_add_library/native_add_library.dart)
dart-lang/native#3      main (file:///c:/workspace/native/pkgs/native_assets_cli/example/native_add_app/bin/native_add_app.dart:9)
dart-lang/native#4      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297)
dart-lang/native#5      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184)

The relative lookup of the native assets seems to be dependent on the location of the executable file, but not the resolved executable file. Note that this behavior is only present on Windows. Performing the same on macOS/Linux works.

$ dart --enable-experiment=native-assets build bin/native_add_app.dart
$ ./bin/native_add_app/native_add_app.exe
Invoking a native function to calculate 1 + 2.
Invocation success: 1 + 2 = 3.
$ ln -s ./bin/native_add_app/native_add_app.exe native_add_app.exe 
$ ./native_add_app.exe
Invoking a native function to calculate 1 + 2.
Invocation success: 1 + 2 = 3.

This came up when bundling an AOT-compiled CLI for Windows which requires using execution aliases on Windows (e.g. symlinks). There are currently no good workarounds for this, in part because the eventual path of the resolved exe is unknown at compilation time -- best I have found is downloading the DLL separately to a known path and using DynamicLibrary.open to trick the native assets feature into working.

Metadata

Metadata

Assignees

Labels

area-dart-cliUse area-dart-cli for issues related to the 'dart' command like tool.area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.dart-cli-buildlibrary-ffitriagedIssue has been triaged by sub team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions