<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 21.09.2017, at 13:15, Frank Muller <<a href="mailto:frank.muller.erl@gmail.com" class="">frank.muller.erl@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><div dir="auto" class="">Stefan,</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">By statically linking bins, Joe is talking about the executables here (erl.exe, ...), not the beam files IMHO.</div></div></div></blockquote><div><br class=""></div>But what you can do is preload all needed beam files, which means they get baked into your erts executable.</div><div><br class=""></div><div>So you can even have statically linked beam files.  Every Erlang system has some of those since quite a lot</div><div>of the system startup is done in Erlang already.   And to get to the point where the runtime can load beam files</div><div>you need some preexisting beam files.</div><div><br class=""></div><div>When building this is done by this perl script and its surrounding Makefile magic:</div><div><br class=""></div><div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">erts/emulator/utils/make_preload </span></div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Which generates a C file called </span>preload.c starting like:</div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">/*</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> * DO NOT EDIT THIS FILE.  It was automatically generated</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> * by the `make_preload' program on Fri Jun 23 12:55:01 2017.</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> */</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">unsigned preloaded_size_otp_ring0 = 532;</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">unsigned char preloaded_otp_ring0[] = {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">0x46,0x4f,0x52,0x31,0x00,0x00,0x02,0x0c, /* FOR1.... */</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  0x42,0x45,0x41,0x4d,0x41,0x74,0x6f,0x6d, /* BEAMAtom */</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  0x00,0x00,0x00,0x82,0x00,0x00,0x00,0x10, /* ........ */</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  0x09,0x6f,0x74,0x70,0x5f,0x72,0x69,0x6e, /* .otp_rin */</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  0x67,0x30,0x05,0x73,0x74,0x61,0x72,0x74, /* g0.start */</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  0x04,0x62,0x6f,0x6f,0x74,0x04,0x69,0x6e, /* .<a href="http://boot.in" class="">boot.in</a> */</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  0x69,0x74,0x03,0x72,0x75,0x6e,0x06,0x65, /* it.run.e */</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  0x72,0x6c,0x61,0x6e,0x67,0x11,0x66,0x75, /* rlang.fu */</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  0x6e,0x63,0x74,0x69,0x6f,0x6e,0x5f,0x65, /* nction_e */</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  0x78,0x70,0x6f,0x72,0x74,0x65,0x64,0x05, /* xported. */</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  0x66,0x61,0x6c,0x73,0x65,0x04,0x74,0x72, /* <a href="http://false.tr" class="">false.tr</a> */</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  0x75,0x65,0x05,0x66,0x61,0x74,0x61,0x6c, /* ue.fatal */</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  0x05,0x65,0x72,0x72,0x6f,0x72,0x06,0x6d, /* .error.m */</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  0x6f,0x64,0x75,0x6c,0x65,0x07,0x64,0x69, /* odule.di */</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">And I suppose that you still can hot code load preloaded files, its just that their memory isn’t freed</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">since it is in the erts executable.</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class="">Best,</div><div class="">-- Peer </div></span></div><div style="margin: 0px; font-size: 10px; line-height: normal; font-family: Monaco; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div><div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><div dir="auto" class=""><br class=""></div><div dir="auto" class="">You'll be able to reload your beam modules on the fly, obviously.</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Moreover, nothing prevent a statically built executable to load a shared lib while running.</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">@Joe: just made a quick search and found UPX binary packer. It's cross-platform:</div><div dir="auto" class=""><a href="https://upx.github.io/" class="">https://upx.github.io/</a></div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Can you please try to shrink the minimal VM binaries on Windows and report back the new size?</div><div dir="auto" class="">Use: upx.exe -9 ...</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">/Frank</div><br class=""><div class="gmail_quote"><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="">
><br class="">
> So my first question is - how can I compile Erlang into a single file<br class="">
> executable? - I want no scripts/batch files to launch erlang no DLLs<br class="">
> and a statically linked binary?<br class="">
<br class="">
Getting rid of scripts/batch files you can do if you generalize the erlexec binary a bit (in Docker for instance, as it was mentioned before, you perhaps want to be able to configure more things with environment variables for instance) but what would "statically linked" mean in the world of modules that load shared objects and even modules that can be upgraded? To statically link one would have to sacrifice the dynamic code reload, right?<br class="">
<br class="">
/Stefan<br class="">
<br class="">
><br class="">
> /Joe<br class="">
><br class="">
><br class="">
><br class="">
> On Wed, Sep 20, 2017 at 4:34 PM, Frank Muller<br class="">
> <<a href="mailto:frank.muller.erl@gmail.com" target="_blank" class="">frank.muller.erl@gmail.com</a>> wrote:<br class="">
>> Do you think it's possible to package this minimal distribution in one<br class="">
>> excutable?<br class="">
>><br class="">
>> Imagine we can ship a whole release in one binary (like in Go).<br class="">
>><br class="">
>> /Frank<br class="">
>><br class="">
>> Wed 20 sept. 2017 at 16:23, Joe Armstrong <<a href="mailto:erlang@gmail.com" target="_blank" class="">erlang@gmail.com</a>> wrote :<br class="">
>>><br class="">
>>> Thanks everybody for you help - I got it down to 5.5MB in 9 files<br class="">
>>> Relocated as follows. I've also packed/compressed the libraries<br class="">
>>><br class="">
>>> Here are the files that are needed<br class="">
>>><br class="">
>>> %% DEST/bin/erl.exe                     120320 bytes<br class="">
>>> %% DEST/bin/start.boot                    5603 bytes<br class="">
>>> %% DEST/erts-9.0/bin/beam.smp.dll      3346944 bytes<br class="">
>>> %% DEST/erts-9.0/bin/erlexec.dll        162304 bytes<br class="">
>>> %% DEST/erts-9.0/bin/inet_gethost.exec   45568 bytes<br class="">
>>> %% DEST/lib/compiler-7.1.ez             409091 bytes<br class="">
>>> %% DEST/lib/kernel-5.2.ez               384730 bytes<br class="">
>>> %% DEST/lib/sasl-3.0.4.ez               106278 bytes<br class="">
>>> %% DEST/lib/stdlib-3.4.ez               913013 bytes<br class="">
>>><br class="">
>>> This seems to work :-)<br class="">
>>><br class="">
>>> Cheers<br class="">
>>><br class="">
>>> /Joe<br class="">
>>><br class="">
>>> On Wed, Sep 20, 2017 at 2:24 PM, Dmitry Kolesnikov<br class="">
>>> <<a href="mailto:dmkolesnikov@gmail.com" target="_blank" class="">dmkolesnikov@gmail.com</a>> wrote:<br class="">
>>>> Hello,<br class="">
>>>><br class="">
>>>> On 20 Sep 2017, at 13.35, Stu Bailey <<a href="mailto:stu.bailey@gmail.com" target="_blank" class="">stu.bailey@gmail.com</a>> wrote:<br class="">
>>>><br class="">
>>>> "As an afterthought - it would be *very nice* to have a program which<br class="">
>>>> makes a minimal distributable program for Windows/Mac/Linux."<br class="">
>>>><br class="">
>>>><br class="">
>>>> This program is called relx.<br class="">
>>>><br class="">
>>>> It generates a release package which are deployable to any vanilla linux<br class="">
>>>> or<br class="">
>>>> other vanilla os.<br class="">
>>>> The usage of Docker-image-with-Erlang complicates the process of<br class="">
>>>> distribution.<br class="">
>>>><br class="">
>>>> Best Regards,<br class="">
>>>> Dmitry<br class="">
>>>><br class="">
>>>><br class="">
>>> _______________________________________________<br class="">
>>> erlang-questions mailing list<br class="">
>>> <a href="mailto:erlang-questions@erlang.org" target="_blank" class="">erlang-questions@erlang.org</a><br class="">
>>> <a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank" class="">http://erlang.org/mailman/listinfo/erlang-questions</a><br class="">
> _______________________________________________<br class="">
> erlang-questions mailing list<br class="">
> <a href="mailto:erlang-questions@erlang.org" target="_blank" class="">erlang-questions@erlang.org</a><br class="">
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank" class="">http://erlang.org/mailman/listinfo/erlang-questions</a><br class="">
</blockquote></div></div>
_______________________________________________<br class="">erlang-questions mailing list<br class=""><a href="mailto:erlang-questions@erlang.org" class="">erlang-questions@erlang.org</a><br class="">http://erlang.org/mailman/listinfo/erlang-questions<br class=""></div></blockquote></div><br class=""></body></html>