Skip to content

dart build cli embeds Windows path separators for Linux native assets when cross-compiling from Windows #63953

Closed

Description

@dzylikecode

dart version: 3.14.0-82.0.dev

When using dart build cli on Windows to build a Linux target with native assets, the generated bundle embeds the native asset relative path using Windows path separators.

For example, building on Windows for Linux produces a native asset path like:

..\lib\libcserialport.so

Then when the bundle is run on Linux, Dart tries to resolve:

/home/.../bundle/bin/..\lib\libcserialport.so

Linux treats backslashes as normal filename characters, not path separators, so the dynamic library cannot be found.

Repro

  1. On Windows, build a CLI app that depends on a bundled native asset, for example cserialport.
  2. Cross-compile to Linux:
dart build cli --target-os linux --target-arch x64
  1. Copy the generated build/cli/linux_x64/bundle/ to Linux.
  2. Run the executable:
./bin/list_ports

Actual result

Unhandled exception:
Invalid argument(s): Couldn't resolve native function 'CSerialPortAvailablePortInfosFree' ...
Failed to load dynamic library '..\lib\libcserialport.so' relative to '/home/.../bundle/bin/list_ports'

Expected result

The embedded Linux native asset path should use POSIX separators:

../lib/libcserialport.so

and the library should load successfully from:

bundle/lib/libcserialport.so

Likely cause

The native assets kernel/YAML serialization appears to call Uri.toFilePath() using the host platform default. When the host is Windows, relative asset paths are serialized with \, even if the target platform is Linux.

The path serialization should probably use the target OS, not the host OS, for example:

uri.toFilePath(windows: target.os == OS.windows)

This affects at least bundled dynamic native assets used by dart build cli cross-compilation from Windows to Linux.

Activity

  1. added
    area-dart-cliUse area-dart-cli for issues related to the 'dart' command like tool.
    on Aug 5, 2026
  2. bkonyi commented on Aug 5, 2026

    @bkonyi
    Contributor
  3. dcharkes commented on Aug 5, 2026

    @dcharkes
    Contributor

    cc @brianquinlan who added support in 212c720 last month.

  4. self-assigned this
    on Aug 23, 2026
  5. brianquinlan commented on Aug 24, 2026

    @brianquinlan
    Contributor

    I started look at this.

    This seems like a real problem and I have exact ideas on how to fix it. The thing that's messing with me is that I remember testing this. I remember doing cross compilation on Windows and then using WSL to run the binary and it worked. Why did it work?

  6. brianquinlan commented on Aug 24, 2026

    @brianquinlan
    Contributor

    Probably what happened is that I accessed the binary through /mnt/c. Using /mnt/c from WSL eventually ends up making calls to Windows, which treats backslash correctly.

  7. brianquinlan commented on Aug 25, 2026

    @brianquinlan
    Contributor
    C:\Users\brian\Dart\cross-compile> dart build cli --target-os=linux --target-arch=x64
    Running build hooks... (1.9s)
    Running link hooks...
    Copying 1 build assets:
    package:sqlite3/src/ffi/libsqlite3.g.dart
    Generated: c:\users\brian\dart\cross-compile\build\cli\linux_x64\bundle\bin\cross_compile
    C:\Users\brian\Dart\cross-compile> python
    Python 3.13.0 (tags/v3.13.0:60403a5, Oct  7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> x = open(r'C:\users\brian\dart\cross-compile\build\cli\linux_x64\bundle\bin\cross_compile', 'rb').read()
    >>> x.find(b'sqlite3.so')
    5938970
    >>> x[5938970-20:5938970+20]
    b'\xb0\x17(\x00\x00\x00\x00\x00\x00\x00..\\lib\\libsqlite3.so\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    >>> x.find(b'sqlite3.so', 5938970+1)
    -1

    So we are embedding the wrong string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-dart-cliUse area-dart-cli for issues related to the 'dart' command like tool.dart-cli-build

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions