{"id":6264,"date":"2018-12-21T20:39:55","date_gmt":"2018-12-21T19:39:55","guid":{"rendered":"https:\/\/pi3g.com\/?p=6264"},"modified":"2018-12-21T20:39:55","modified_gmt":"2018-12-21T19:39:55","slug":"crystal-alpine-on-the-raspberry-pi","status":"publish","type":"post","link":"https:\/\/pi3g.com\/de\/crystal-alpine-on-the-raspberry-pi\/","title":{"rendered":"Crystal und Alpine auf dem Raspberry Pi"},"content":{"rendered":"<p>Bringing together two interesting technologies:<\/p>\n<ul>\n<li>Alpine Linux \u2013 a small-size and security oriented Linux distribution<\/li>\n<li>Crystal \u2013 a compiled language with a nice syntax (similar to Ruby)<\/li>\n<li>on the Raspberry Pi (armhf \/ ARMv6, which would also support the Pi Zero W)<\/li>\n<\/ul>\n<p>is not possible currently, as of 21.12.2018.<\/p>\n<p><strong>There is no (at least no easy) way to cross-compile Crystal applications for the Raspberry Pi and Alpine Linux, from, for instance, x86 platforms, as the necessary target <font style=\"background-color: rgb(255, 255, 0);\">arm-linux-musleabihf<\/font> is not supported yet.<\/strong><\/p>\n<p><\/p>\n<h3>Misc background information<\/h3>\n<p>Unfortunately it\u2019s not possible to compile crystal on Alpine\/ARM\/Raspberry using gcc or the like, as \u201cto compile Crystal you need Crystal\u201d \u2013 the compilation will fail:<\/p>\n<blockquote>\n<p>pitest:\/usr\/local\/crystal\/crystal# make<br \/>\nUsing \/usr\/bin\/llvm-config [version=5.0.1]<br \/>\ng++ -c&nbsp; -o src\/llvm\/ext\/llvm_ext.o src\/llvm\/ext\/llvm_ext.cc -I\/usr\/lib\/llvm5\/include -Os -founused-parameter <br \/>-Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-fdata-sections -Os <br \/>-fomit-frame-pointer -Os -DNDEBUG&nbsp; -fno-exceptions -DLLVM_BUILD_GLOBAL_ISD__STDC_LIMIT_MACROS<br \/>\ncc -fPIC&nbsp;&nbsp;&nbsp; -c -o src\/ext\/sigfault.o src\/ext\/sigfault.c<br \/>\nar -rcs src\/ext\/libcrystal.a src\/ext\/sigfault.o<br \/>\nCRYSTAL_CONFIG_PATH=&#8221;\/usr\/local\/crystal\/crystal\/src&#8221; CRYSTAL_CONFIG_BUILD_COMMIT=&#8221;74c65ce6b&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lib<br \/><strong><br \/>\nYou need to have a crystal executable in your path!<\/strong><br \/>\nmake: *** [Makefile:123: .build\/crystal] Error 1<\/p>\n<\/blockquote>\n<p>The idea is that you crosscompile crystal on another architecture, and then can use it to natively compile it.<\/p>\n<p>Alpine Linux uses musl, an alternative libc.<\/p>\n<p>To find out the name of the target (LLVM target triple), you can execute llvm-config on the target system, like this:<\/p>\n<blockquote>\n<p>llvm-config &#8211;host-target<\/p>\n<\/blockquote>\n<p>To be able to run this command on Alpine, you install two packages:<\/p>\n<blockquote>\n<p>apk add llvm<\/p>\n<p>apk add llvm-dev<\/p>\n<\/blockquote>\n<p>When trying a target which Crystal does not support yet for crosscompilation, you will get this error message:<\/p>\n<blockquote>\n<p><strong>in \/usr\/share\/crystal\/src\/callstack.cr:3: while requiring &#8220;c\/dlfcn&#8221;: can&#8217;t find file &#8216;c\/dlfcn&#8217;<\/strong><\/p>\n<\/blockquote>\n<p>These libraries are located here:<\/p>\n<blockquote>\n<p>\/usr\/share\/crystal\/src\/lib_c<\/p>\n<\/blockquote>\n<p>Crystal is supported on Alpine, on the aarch64 (ARM 64bit) and x86_64 platforms. (and x86 via portalier.com)<\/p>\n<p>In general, crosscompiling with Crystal works like this:<\/p>\n<blockquote>\n<p>crystal build &#8211;release &#8211;cross-compile &#8211;target &#8220;aarch64-linux-musl&#8221; src\/armtest.cr<\/p>\n<\/blockquote>\n<p>it will give you a command line to execute on the target machine:<\/p>\n<blockquote>\n<p>cc &#8216;armtest.o&#8217; -o &#8216;armtest&#8217;&nbsp; -rdynamic&nbsp; -lpcre -lgc -lpthread \/usr\/share\/crystal\/src\/ext\/libcrystal.a -levent -lrt -L\/usr\/lib -L\/usr\/local\/lib<\/p>\n<\/blockquote>\n<h3><\/h3>\n<h3>See these references:<\/h3>\n<ul>\n<li><a title=\"https:\/\/github.com\/crystal-lang\/crystal\/issues\/4391\" href=\"https:\/\/github.com\/crystal-lang\/crystal\/issues\/4391\">https:\/\/github.com\/crystal-lang\/crystal\/issues\/4391<\/a><\/li>\n<li><a title=\"https:\/\/crystal-lang.org\/docs\/installation\/from_source_repository.html\" href=\"https:\/\/crystal-lang.org\/docs\/installation\/from_source_repository.html\">https:\/\/crystal-lang.org\/docs\/installation\/from_source_repository.html<\/a><\/li>\n<li><a title=\"https:\/\/irclog.whitequark.org\/crystal-lang\/2017-08-12\" href=\"https:\/\/irclog.whitequark.org\/crystal-lang\/2017-08-12\">https:\/\/irclog.whitequark.org\/crystal-lang\/2017-08-12<\/a><\/li>\n<li><a title=\"https:\/\/github.com\/TheKernelCorp\/NuummiteOS\" href=\"https:\/\/github.com\/TheKernelCorp\/NuummiteOS\">https:\/\/github.com\/TheKernelCorp\/NuummiteOS<\/a> (proof of concept OS kernel written in Crystal)<\/li>\n<li><a title=\"https:\/\/crystal-lang.org\/docs\/installation\/on_alpine_linux.html\" href=\"https:\/\/crystal-lang.org\/docs\/installation\/on_alpine_linux.html\">https:\/\/crystal-lang.org\/docs\/installation\/on_alpine_linux.html<\/a><\/li>\n<li><a title=\"http:\/\/public.portalier.com\/alpine\/\" href=\"http:\/\/public.portalier.com\/alpine\/\">http:\/\/public.portalier.com\/alpine\/<\/a> \u2013 packages for x86 as well<\/li>\n<li><a title=\"https:\/\/github.com\/ysbaddaden\/crystal-alpine\" href=\"https:\/\/github.com\/ysbaddaden\/crystal-alpine\">https:\/\/github.com\/ysbaddaden\/crystal-alpine<\/a><\/li>\n<li><a title=\"https:\/\/wiki.musl-libc.org\/supported-platforms.html\" href=\"https:\/\/wiki.musl-libc.org\/supported-platforms.html\">https:\/\/wiki.musl-libc.org\/supported-platforms.html<\/a><\/li>\n<li><a title=\"https:\/\/github.com\/ysbaddaden\/crystal-alpine\/issues\/6\" href=\"https:\/\/github.com\/ysbaddaden\/crystal-alpine\/issues\/6\">https:\/\/github.com\/ysbaddaden\/crystal-alpine\/issues\/6<\/a><\/li>\n<li><a title=\"https:\/\/github.com\/crystal-lang\/crystal\/pull\/5862\" href=\"https:\/\/github.com\/crystal-lang\/crystal\/pull\/5862\">https:\/\/github.com\/crystal-lang\/crystal\/pull\/5862<\/a> &lt;- issue about arm-linux-musleabihf<\/li>\n<li><a title=\"https:\/\/github.com\/crystal-lang\/crystal\/issues\/5467\" href=\"https:\/\/github.com\/crystal-lang\/crystal\/issues\/5467\">https:\/\/github.com\/crystal-lang\/crystal\/issues\/5467<\/a><\/li>\n<li><a title=\"https:\/\/pkgs.alpinelinux.org\/packages?name=crystal&amp;branch=edge\" href=\"https:\/\/pkgs.alpinelinux.org\/packages?name=crystal&amp;branch=edge\">https:\/\/pkgs.alpinelinux.org\/packages?name=crystal&amp;branch=edge<\/a> &lt;- packages by Jakub Jirutka for Crystal, for Alpine. He tried to build it for armhf as well, but did not succeed <\/li>\n<li><a title=\"https:\/\/elinux.org\/images\/e\/eb\/Transitioning_From_uclibc_to_musl_for_Embedded_Development.pdf\" href=\"https:\/\/elinux.org\/images\/e\/eb\/Transitioning_From_uclibc_to_musl_for_Embedded_Development.pdf\">https:\/\/elinux.org\/images\/e\/eb\/Transitioning_From_uclibc_to_musl_for_Embedded_Development.pdf<\/a> &lt;- interesting background information about musl<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Zusammenf\u00fchrung von zwei interessanten Technologien: Alpine Linux - eine kleine und sicherheitsorientierte Linux-Distribution Crystal - eine kompilierte Sprache mit einer sch\u00f6nen Syntax (\u00e4hnlich Ruby) auf dem Raspberry Pi (armhf \/ ARMv6, die auch den Pi Zero W unterst\u00fctzen w\u00fcrde) ist derzeit nicht m\u00f6glich, Stand 21.12.2018. Es gibt keine (zumindest keine...<\/p>","protected":false},"author":830,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[401,416,400],"tags":[417,419,409,418,369],"class_list":["post-6264","post","type-post","status-publish","format-standard","hentry","category-alpine-linux","category-crystal-language","category-raspberry-pi-embedded-development","tag-alpine","tag-crosscompilation","tag-crystal","tag-musl","tag-raspberry"],"_links":{"self":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/6264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/users\/830"}],"replies":[{"embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/comments?post=6264"}],"version-history":[{"count":1,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/6264\/revisions"}],"predecessor-version":[{"id":6265,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/6264\/revisions\/6265"}],"wp:attachment":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/media?parent=6264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/categories?post=6264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/tags?post=6264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}