Description
When compiling System.IO.Ports tests on NativeAOT+Linux (build.sh clr.aot+libs -rc Release -lc Release
followed by dotnet build System.IO.Ports.Tests.csproj -p:TestNativeAot=true -p:RuntimeConfiguration=Release -p:LibrariesConfiguration=Release
), the test doesn't copy libSystem.IO.Ports.Native.so to the output directory and we get:
Running assembly:System.IO.Ports.Tests, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
Installed ports : /dev/ttyS0,/dev/ttyS1
Exception opening port /dev/ttyS0: System.DllNotFoundException: Unable to load shared library 'libSystem.IO.Ports.Native' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable:
libSystem.IO.Ports.Native.so: cannot open shared object file: No such file or directory
liblibSystem.IO.Ports.Native.so: cannot open shared object file: No such file or directory
libSystem.IO.Ports.Native: cannot open shared object file: No such file or directory
liblibSystem.IO.Ports.Native: cannot open shared object file: No such file or directory
at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x4e
at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x103
at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x35
at Interop.Serial.<SerialPortOpen>g____PInvoke|0_0(Byte*) + 0x22
at Interop.Serial.SerialPortOpen(String) + 0x82
at System.IO.Ports.SafeSerialDeviceHandle.Open(String) + 0x1c
at System.IO.Ports.SerialStream..ctor(String, Int32, Parity, Int32, StopBits, Int32, Int32, Handshake, Boolean, Boolean, Boolean, Byte) + 0xcb
at System.IO.Ports.SerialPort.Open() + 0xee
at Legacy.Support.TCSupport.CheckPortsCanBeOpened(IEnumerable`1) + 0xdd
This works for customer scenarios since the library is a native asset in the NuGet package. It just blocks running the tests in this repo.
Running System.IO.Ports tests will be blocked on this issue for non-Windows platforms.
Not sure why this works with JITted runtimes. Do we just dump the .so into the runtimepack even though it's not an inbox assembly? If we fix this the "right way" for JITted runtime (make sure the .so is next to the executable, the same way it will be there for customers), NativeAOT fix will just fall out.