diff --git a/ffi/dart/hook/link.dart b/ffi/dart/hook/link.dart index 0bc82857069..c5acdadc11b 100644 --- a/ffi/dart/hook/link.dart +++ b/ffi/dart/hook/link.dart @@ -58,13 +58,16 @@ Future main(List args) async { packageName: input.packageName, assetName: 'src/bindings/lib.g.dart', sources: [staticLib.file!.toFilePath()], - libraries: - // On Windows, icu4x.lib is lacking /DEFAULTLIB directives to advise - // the linker on what libraries to link against. To make up for that, - // the libraries used have to be provided to the linker explicitly. - input.config.code.targetOS == OS.windows - ? const ['MSVCRT', 'ws2_32', 'userenv', 'ntdll'] - : const [], + libraries: switch (input.config.code.targetOS) { + // On Windows, icu4x.lib is lacking /DEFAULTLIB directives to advise + // the linker on what libraries to link against. To make up for that, + // the libraries used have to be provided to the linker explicitly. + OS.windows => const ['MSVCRT', 'ws2_32', 'userenv', 'ntdll'], + // On Android, libm (math library) is not linked by default, but math + // functions like `expf` referenced in Rust libicu4x require libm. + OS.android => const ['m'], + _ => const [], + }, linkerOptions: LinkerOptions.treeshake(symbolsToKeep: usedSymbols), ).run( input: input,