It is currently Thu Nov 26, 2020 10:06 am
All times are UTC + 8 hours

build native app without installing GCC toolchain

Who doesn't love third-party apps? Get together and talk about them here.

build native app without installing GCC toolchain

Postby core » Fri Jun 12, 2020 3:09 pm

[edited: using base /usr/local/AppCentral/opt instead of /opt]

I wanted to build my favorite editor VILE for use on the Asustor NAS. But I quickly discovered that the GCC toolchain is not installed. I didn't want to go down the rabbit hole of installing gcc and whatever dependencies I needed. It could be done, but I don't think is good practice to be installing so many tools. For all I know, something installed might interfere with tools needed for normal operation or the upgrade process.

So knowing that Docker is a good solution for this sort of problem I started looking for minimal dev environments already available. In Docker Official Images, I found gcc image on dockerhub. The instructions are pretty simple and clear. But I needed to run multiple commands and I wanted to abstract it so I could easily modify for other apps. The result is simplified down to this flow:

  1. Download and unzip/untar source code to SRC_PATH (substituting SRC_PATH with wherever makes sense on your NAS). For me, this is the 'vile' editor source (from vile-9.8u) extracted to /volume1/home/me/ext/vile/vile-9.8u.
  2. Decide where to install on the NAS. A good choice might be a directory under /usr/local/AppCentral/opt. I'm using /usr/local/AppCentral/opt/vile and this path is passed in during my configuration step for the build.
  3. Outside your source code directory create the installer.sh script below.
    • Customize your build and install steps.
    • Customize a volume which binds an outer install path to the inner container path or remove it if you don't need it (in my case it is /usr/local/AppCentral/opt/vile; don't change the volume binding /usr/src/myapp).
    • Customize the GCC version if it is important (I didn't modify this from the documentation for the gcc docker image; there are pro's and con's for forcing the version).
  4. Run: ./installer.sh SRC_PATH
  5. Enjoy your app (in my case supporting files installed under /usr/local/AppCentral/opt/vile with main binary /usr/local/AppCentral/opt/vile/bin/vile). 8-)

installer.sh
Code: Select all
#!/bin/sh
# pull gcc Docker container and run with given embedded command script

cd $1
CMD=__cmd.sh

cat > $CMD <<EOF
#!/bin/sh
# script you want to run inside container
# (e.g. steps to build & install app)

./configure --prefix=/usr/local/AppCentral/opt/vile
make
make install
EOF

chmod +x $CMD
docker run --rm \
    -v /opt/vile:/opt/vile \
    -v "$PWD":/usr/src/myapp \
    -w /usr/src/myapp gcc:4.9 ./$CMD


I hope you find this useful. This may be helpful in early steps on your way to creating binaries needed for your next App Central app.
Last edited by core on Wed Jul 01, 2020 4:41 pm, edited 1 time in total.
AS6208T + AS6004U
User avatar
core
 
Posts: 19
Joined: Sat May 16, 2020 5:12 am

Re: build native app without installing GCC toolchain

Postby core » Sun Jun 14, 2020 3:17 pm

[edited: using base /usr/local/AppCentral/opt instead of /opt]

Here is a followup example for another favorite app... GNU Screen.

If you're not familiar with Screen, it allows you to create a persistent session on your server with multiple windows (Google: gnu screen tutorial). FYI, a more modern alternative to screen is TMUX (Google: gnu screen vs tmux).

screen_installer.sh
Code: Select all
#!/bin/sh
# 1. download screen source code
# 2. extract source code
# 3. pull gcc Docker container and run commands which build & install

APP_VERSION=screen-4.8.0

ARCHIVE=$APP_VERSION.tar.gz
wget http://ftp.gnu.org/gnu/screen/$ARCHIVE
tar -zxf $ARCHIVE
cd $APP_VERSION

PREFIX=/usr/local/AppCentral/opt/screen
CMD=__cmd.sh
cat > $CMD <<EOF
#!/bin/sh
# script you want to run inside container
# (e.g. steps to build & install app)

./configure --prefix=$PREFIX
make
make install
EOF

chmod +x $CMD
docker run --rm \
    -v $PREFIX:$PREFIX \
    -v "$PWD":/usr/src/myapp \
    -w /usr/src/myapp gcc:4.9 ./$CMD


Last edited by core on Wed Jul 01, 2020 4:42 pm, edited 1 time in total.
AS6208T + AS6004U
User avatar
core
 
Posts: 19
Joined: Sat May 16, 2020 5:12 am

Re: build native app without installing GCC toolchain

Postby father.mande » Sun Jun 14, 2020 4:06 pm

Hi,

Just F.Y.I. (because it's not a contest :lol: )
... docker is a solution ... but need to add docker management ... and be sure that libs are at the same level (or program don't require updated version) ... unfortunately A.D.M. used 2.22 for libc.
... like you I don't use the toolchain provide in Asustor developer corner web site

BUT other solutions exist :roll: :
1 use a chroot ... easy to build in one command ... and after any possibilities is open (including gcc and others dev. tools with all include and make, autoconf, etc. tools )

2 use Entware APKG ...
... Entware bring +1900 packages (same as in Openwrt) to the Asustor NAS ... as native application with libc 2.27
... ... ex. you can get complete version of screen, tmux, all full G.N.U. tools, etc.
... Entware also provide native ggc (and all include files (to download from the package web site)) + package manager if you want to propose your dev. for all user
... LAST Entware support all the Asustor platform in the same manner : x86_64, armhf (v7l) 32 bits, Arm64 (aarch64) and x32 (i386) ... so you can generate on any platform you own.

3 use any Linux distribution (even new)
... no change for dev. BUT
... need to extract all libraries used to port them with the program (easy one shell script available on the Web)
... this is a good solution for complex X11 graphic application or media player to do a port.

For my own (for my APKG like myHD, or PlexMediaPlayer etc. ) I use one of this solution depends of the target
ex. :
for building strace supporting malformed (with letter) kernel version (in A.D.M.) ... a chroot
for compiling extra kernel modules ... or simple (not already done (+1900 packages)) utilities ... Entware
for compiling X11 applications ... an Ubuntu V.M.

Big advantage of Linux ... lot of solutions for the same problem and don't redo things already done ... except if you add or solve some things (ex. I have posted the strace change request to the dev. site to obtain a solution (certainly better than mine) ... perhaps integrate in the "default" code (or not) in the future.

Philippe.
AS5202T /AS5002T / AS202TE / AS1002T
My Blog specific to my APKG : https://blog.father-mande.ovh/
User avatar
father.mande
 
Posts: 1047
Joined: Sat Sep 12, 2015 2:55 am

Re: build native app without installing GCC toolchain

Postby core » Sun Jun 14, 2020 6:02 pm

Hi Philippe, Thanks for that info.

FYI, With the GCC Docker image I didn't need to do anything special (e.g. regarding libc). The result is a compiled binary that runs outside the container.
AS6208T + AS6004U
User avatar
core
 
Posts: 19
Joined: Sat May 16, 2020 5:12 am

Return to Developer's Corner

  • You cannot post new topics in this forum
    You cannot reply to topics in this forum
    You cannot edit your posts in this forum
    You cannot delete your posts in this forum
    You cannot post attachments in this forum
  • Who is online

    Users browsing this forum: No registered users and 1 guest