{"action":"opened","issue":{"url":"https://api.github.com/repos/mrfoto/slacker/issues/1","repository_url":"https://api.github.com/repos/mrfoto/slacker","labels_url":"https://api.github.com/repos/mrfoto/slacker/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/mrfoto/slacker/issues/1/comments","events_url":"https://api.github.com/repos/mrfoto/slacker/issues/1/events","html_url":"https://github.com/mrfoto/slacker/issues/1","id":306203445,"number":1,"title":"Alternative crystal cross-compiling","user":{"login":"faustinoaq","id":3067335,"avatar_url":"https://avatars2.githubusercontent.com/u/3067335?v=4","gravatar_id":"","url":"https://api.github.com/users/faustinoaq","html_url":"https://github.com/faustinoaq","followers_url":"https://api.github.com/users/faustinoaq/followers","following_url":"https://api.github.com/users/faustinoaq/following{/other_user}","gists_url":"https://api.github.com/users/faustinoaq/gists{/gist_id}","starred_url":"https://api.github.com/users/faustinoaq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/faustinoaq/subscriptions","organizations_url":"https://api.github.com/users/faustinoaq/orgs","repos_url":"https://api.github.com/users/faustinoaq/repos","events_url":"https://api.github.com/users/faustinoaq/events{/privacy}","received_events_url":"https://api.github.com/users/faustinoaq/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-18T00:53:17Z","updated_at":"2018-03-18T00:53:17Z","closed_at":null,"author_association":"NONE","body":"@mrfoto This is an awesome project!\r\n\r\nI'm using Raspberry Pi too :+1: \r\n\r\nI know [portalier package](http://public.portalier.com/raspbian/) is a bit outdated, so I use cross-compiling:\r\n\r\n> **Requirements:** RPi (`gcc`, `libprce3-dev`, `libevent-dev`, `libssl-dev`) PC (`llvm`)\r\n\r\n1. Cross-compile the object file on your dev computer (see output)\r\n\r\n> **Note:** Tempfile isn't supported on arm yet, comment these lines on Kemal:\r\n\r\nhttps://github.com/kemalcr/kemal/blob/6fbad555d05bd3ac3735adf7abdca08927cfee25/src/kemal/file_upload.cr#L13-L16\r\n\r\n_Also remember to comment `getter tmpfile : Tempfile` at line 4_\r\n\r\n```sh\r\ncrystal build server.cr --cross-compile --target=\"arm-unknown-linux-gnueabihf\" -s\r\nParse:                             00:00:00.000236778 (   0.25MB)\r\nSemantic (top level):              00:00:01.272815827 ( 100.45MB)\r\nSemantic (new):                    00:00:00.002450326 ( 100.45MB)\r\nSemantic (type declarations):      00:00:00.037667248 ( 108.45MB)\r\nSemantic (abstract def check):     00:00:00.002489012 ( 108.45MB)\r\nSemantic (ivars initializers):     00:00:00.012113343 ( 108.45MB)\r\nSemantic (cvars initializers):     00:00:00.011383142 ( 108.45MB)\r\nSemantic (main):                   00:00:01.165512252 ( 172.82MB)\r\nSemantic (cleanup):                00:00:00.001283736 ( 172.82MB)\r\nSemantic (recursive struct check): 00:00:00.001738710 ( 172.82MB)\r\nCodegen (crystal):                 00:00:00.589332905 ( 172.82MB)\r\ncc 'server.o' -o 'server'  -rdynamic  -lz `command -v pkg-config > \\\r\n/dev/null && pkg-config --libs libssl || \\\r\nprintf %s '-lssl -lcrypto'` `command -v pkg-config > \\\r\n/dev/null && pkg-config --libs libcrypto || \\\r\nprintf %s '-lcrypto'` -lyaml -lpcre -lm -lgc -lpthread \\\r\n/usr/lib/crystal/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib\r\n\r\nMacro runs:\r\n - /usr/lib/crystal/ecr/process.cr: 00:00:00.848106195\r\n```\r\n\r\n2. Copy `.o` file to RPi\r\n\r\n3. Create `libcrystal.a` on RPi (linker dependency)\r\n\r\n```sh\r\ngit clone https://github.com/crystal-lang/crystal.git\r\ncd crystal\r\nmake deps # just build libcrystal.a for arm-unknown-linux-gnueabihf architecture\r\n```\r\n\r\nThen check `~/crystal/src/ext/libcrystal.a` has been created :tada: \r\n\r\n4. Create an executable using cross-compiling output (1)\r\n\r\n```\r\ncc 'server.o' -o 'server'  -rdynamic  -lz `command -v pkg-config > \\\r\n/dev/null && pkg-config --libs libssl || \\\r\nprintf %s '-lssl -lcrypto'` `command -v pkg-config > \\\r\n/dev/null && pkg-config --libs libcrypto || \\\r\nprintf %s '-lcrypto'` -lyaml -lpcre -lm -lgc -lpthread \\\r\n/home/pi/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib\r\n```\r\n\r\n_Notice we changed `/usr/lib/crystal/ext/libcrystal.a` by `/home/pi/crystal/src/ext/libcrystal.a`_\r\n\r\nAnd that's all, if you follow these steps you should be able to cross compile your project successfully to RPi\r\n\r\n> **Note:** This process looks a bit complex but is very useful if you don't want to install crystal in your RPi because memory, space requirements and so on.\r\n\r\n### Static compiled binary\r\n\r\nI compiled master https://github.com/mrfoto/slacker/commit/f4baf71661bf7c1c87785db37c1e4469e5566f36 statically using `-static` on linker command (see step 4)\r\n\r\n```sh\r\n$ file server\r\nserver: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked,\r\nfor GNU/Linux 3.2.0, BuildID[sha1]=e1d8796d9ecdb18ab087deaa2e8977eed9acc620, not stripped\r\n$ sha256sum server\r\n7a31e7ee48644fb31596f9682c022450d404cc753e8548cd7864ac472ccb3d05  server\r\n$ ldd server\r\n        not a dynamic executable\r\n```\r\n\r\nTry it! [server.tar.gz](https://github.com/mrfoto/slacker/files/1822223/server.tar.gz) \r\n\r\n:tada: \r\n"}}
{"actor":{"display_login":"faustinoaq"}}