bflattened / bflat

C# as you know it but with Go-inspired tooling (small, selfcontained, and native executables)
GNU Affero General Public License v3.0
3.56k stars 102 forks source link

run in docker #139

Closed atrakic closed 5 months ago

atrakic commented 6 months ago

Hi,

I tried to run in docker from Mac host but I could not succeed. What I tried:

Prepare build + run env

# on Mac host:
$ mkdir -p foo
cd foo
git clone https://github.com/bflattened/bflat.git
mkdir tmp
cd tmp
$ wget -c https://github.com/bflattened/bflat/releases/download/v8.0.1/bflat-8.0.1-linux-glibc-x64.tar.gz
$ cd ..

enter docker

docker run -it  --platform linux/amd64 --rm -v .:/app -w /app debian bash

In docker from here

$  uname -m
x86_64

$ cd tmp 
$ tar xvf bflat-8.0.1-linux-glibc-x64.tar.gz$
$ cd ..
$ export LD_LIBRARY_PATH=:/app/tmp:/app/tmp/lib/linux:/usr/lib:/app/tmp/lib/uefi/x64:/app/tmp/lib
$ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/app/tmp:/app/tmp/bin

Verify install

root@a8d2861d86ca:/app/tmp# ./bflat -v
8.0.1+ce27bc593cdbd0de5afb836c62953f0c40ae32bd

Try to build and run sample:

$ cd /app/bflat/samples/HelloWorld
$ bflat build hello.cs
No usable version of libssl was found
Aborted

Install missing package

$ apt-get install -y libssl3

Try to run again:

$ bflat build hello.cs
Error: DllNotFound_Linux, objwriter,
objwriter.so: cannot open shared object file: No such file or directory
libc++.so.1: cannot open shared object file: No such file or directory
objwriter: cannot open shared object file: No such file or directory
libobjwriter: cannot open shared object file: No such file or directory

System.DllNotFoundException: DllNotFound_Linux, objwriter,
objwriter.so: cannot open shared object file: No such file or directory
libc++.so.1: cannot open shared object file: No such file or directory
objwriter: cannot open shared object file: No such file or directory
libobjwriter: cannot open shared object file: No such file or directory

   at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x47
   at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x127
   at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x35
   at ILCompiler.DependencyAnalysis.ObjectWriter.InitObjWriter(String, String) + 0x43
   at ILCompiler.DependencyAnalysis.ObjectWriter..ctor(String, NodeFactory, ObjectWritingOptions) + 0x19a
   at ILCompiler.DependencyAnalysis.ObjectWriter.EmitObject(String, IReadOnlyCollection`1, NodeFactory, ObjectWritingOptions, IObjectDumper, Logger) + 0x8e
   at ILCompiler.Compilation.ILCompiler.ICompilation.Compile(String, ObjectDumper) + 0x32
   at BuildCommand.Handle(ParseResult) + 0x2fef
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext() + 0x139
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xbe
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4e
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext() + 0xf2
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xbe
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4e
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext() + 0xbf
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xbe
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4e
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseVersionOption>b__0>d.MoveNext() + 0x1dd
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xbe
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4e
   at System.CommandLine.Invocation.InvocationPipeline.<Invoke>g__FullInvocationChain|3_0(InvocationContext) + 0x8a
   at Program.Main(String[] args) + 0x2b4

What else do I miss?

MichalStrehovsky commented 6 months ago

I think it's missing libc++. Try installing libc++1 package.

lucabol commented 5 months ago

fyi I had the same issue on Ubuntu 22.04 under WSL2 and fixed it with:

sudo apt-get -y install libc++1

Perhaps you want to doc this as people are likely to try it in this configuration.

MichalStrehovsky commented 5 months ago

Thanks for verifying. Yep, should doc this.

Luckily upstream is getting rid of objwriter.so, and also the transitive libc++ dependency for .NET 9 so this will soon be past.