MLton on Alpine Linux - alpine-linux

I am encountering problems to install and run the MLton compiler in a Docker container using Alpine Linux.
Is there a way to install this compiler on this system?
Try #1
Using the standard `alpine base image and the binary distribution of MLton:
$ curl http://sourceforge.net/projects/mlton/files/mlton/20130715/mlton-20130715-1.amd64-linux.tgz --output mlton-20130715-1.amd64-linux.tgz
$ docker build .
With the following Dockerfile:
FROM alpine
COPY mlton-20130715-1.amd64-linux.tgz /
RUN apk add --no-cache bash build-base gmp-dev linux-headers \
&& tar xf /mlton-20130715-1.amd64-linux.tgz \
--directory /usr/ \
--strip-components 1 \
&& echo 'print "Hello, world!\n";' >> hello-world.sml \
&& mlton hello-world.sml
Docker build fails with the following error message, probably because glibc is missing.
/usr/bin/mlton: line 52: /usr/lib/mlton/mlton-compile: No such file or directory
Try #2
The same as above, with a base Docker image that embeds glibc:
FROM frolvlad/alpine-glibc
This time, mlton runs, but produces the following error:
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/mlton/targets/self/libmlton.a(platform.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
...
/usr/lib/gcc/x86_64-alpine-linux-musl/6.4.0/../../../../x86_64-alpine-linux-musl/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
call to system failed with exit status 1:
gcc -o hello-world /tmp/fileGEluFu.o /tmp/fileYnNjh9.o -L/usr/lib/mlton/targets/self -lmlton -lgdtoa -lm -lgmp -m64 -Wl,-znoexecstack
Any idea on how to solve this problem?

Related

AWS Lambda - Swift Operation not permitted

I am trying to compile Swift code via AWS Lambda.
Therefore I am using an Ubuntu 18.04 Image as base.
The Swift Version is 5.0.1.
When the image is executed locally, it works fine.
When I try to execute it in AWS Lambda, I get the following error:
/usr/bin/ld.gold: fatal error: /tmp/project/src/a.out: Operation not
permitted\nclang-7: error: linker command failed with exit code 1 (use
-v to see invocation)
I think that the problem is caused by the read-only aws lambda container, that only allows to write into the /tmp/ folder.
Do you know how to fix this error? It seems that swift needs permissions for folders, it doesnt have permission for?
Dockerfile
FROM ubuntu:18.04
# install clang
RUN apt-get update
RUN apt-get install -y clang
# install wget
RUN apt-get install -y wget
# install swift dependencies
RUN apt-get install -y libcurl3 libpython2.7 libpython2.7-dev
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get install -y --no-install-recommends \
binutils \
git \
libc6-dev \
libcurl4 \
libedit2 \
libgcc-5-dev \
libpython2.7 \
libsqlite3-0 \
libstdc++-5-dev \
libxml2 \
pkg-config \
tzdata \
zlib1g-dev \
libbsd-dev
RUN apt-get install -y libicu-dev
# install swift 5.0.1
RUN wget https://swift.org/builds/swift-5.0.1-release/ubuntu1804/swift-5.0.1-RELEASE/swift-5.0.1-RELEASE-ubuntu18.04.tar.gz RUN tar xzf swift-5.0.1-RELEASE-ubuntu18.04.tar.gz RUN mv swift-5.0.1-RELEASE-ubuntu18.04 /usr/lib/swift RUN echo "export PATH=/usr/lib/swift/usr/bin:$PATH" >> ~/.bashrc
RUN . ~/.bashrc
RUN chmod -R o+r /usr/lib/swift
This is the command executed in the AWS-Lambda handler function:
swiftc hello_world.swift -o a.out
hello_world.swift
print("Hello World!")
Your output must be set in tmp folder
swiftc hello_world.swift -o /tmp/a.out

Building postgres from source throws "'utils/errcodes.h' file not found" when called from other makefile

I am currently constructing a Makefile and one of the things it will be doing is downloading and building postgres from source. Before starting to write the makefile file I always used the following set of commands to do this:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
cd postgres-REL_13_3
./configure --prefix "`pwd`" --without-readline --without-zlib
make
make install
Executing the above listed commands in the terminal results in the successful installation of postgres. Then I translated these into a makefile which looks as follows:
build:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
cd postgres-REL_13_3 \
&& ./configure --prefix "`pwd`" --without-readline --without-zlib \
&& $(MAKE) \
&& $(MAKE) install
Running this Makefile results in the error:
../../src/include/utils/elog.h:71:10: fatal error: 'utils/errcodes.h' file not found
It seems that something about calling the make from another Makefile causes a referencing issue with the files during the build process, but I just can figure out for the life of me what I have to change to fix this.
It appears to be the influence of Makefile enviromental variables. I didn't discover the exact mechanism, but unsetting them helps.
build:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
unset MAKELEVEL && unset MAKEFLAGS && unset MFLAGS && cd postgres-REL_13_3 \
&& ./configure --prefix "`pwd`" --without-readline --without-zlib \
&& $(MAKE) \
&& $(MAKE) install

Cannot use %install in Swift Colab

I try to install a new library in Swift on Google Colab
%install '.package(url: "https://github.com/IBM-Swift/BlueCryptor.git", from: "1.0.28")' Cryptor
Then, there is an error
...
error: toolchain is invalid: could not find the `swiftc` at expected path /swift/toolchain/usr/bin/swiftc
Install Error: swift-build returned nonzero exit code 1.
But I check that swiftc does exist in /swift/toolchain/usr/bin.
Here's a Colab notebook
that demonstrate the error.
Please help.
Now I update it to the latest Swift version. By running this notebook:
https://colab.research.google.com/github/tensorflow/swift/blob/master/notebooks/install_latest_swift.ipynb
There's no error anymore. So, just need to update it.
You can also do it all from the Swift notebook as well, using this code.
import Python
Python.import("subprocess").getoutput("""
rm -rf /swift
mkdir -p /swift/toolchain
wget -nv -O- https://storage.googleapis.com/s4tf-kokoro-artifact-testing/latest/swift-tensorflow-DEVELOPMENT-cuda10.0-cudnn7-ubuntu18.04.tar.gz | tar xzf - -C /swift/toolchain
wget -nv -O- https://storage.googleapis.com/s4tf-kokoro-artifact-testing/latest/swift-jupyter.tar.gz | tar xzf - -C /swift
python3 /swift/swift-jupyter/register.py --swift-toolchain /swift/toolchain
apt-get install libblocksruntime-dev
""")

Running Mkbootstrap for DBI () => DBIXS.h:22:20: fatal error: EXTERN.h: No such file or directory

I try to install MHA node on a docker container based on Alpine. The container has perl, make and gcc via apk. :
RUN apk add --update perl make gcc
A prerequisite for MHA node is DBD::mysql. The command
perl -MCPAN -e 'install DBD::mysql'
results in the above given error. Google does know nothing about it.
The following commands, needed for MHA manager, do run fine, however:
perl -MCPAN -e "install Config::Tiny"
perl -MCPAN -e "install Log::Dispatch"
perl -MCPAN -e "install Parallel::ForkManager"
The problem obviously is related to DBI:
Running Mkbootstrap for DBI ()
chmod 644 "DBI.bs"
"/usr/bin/perl" -p -e "s/~DRIVER~/Perl/g" ./Driver.xst > Perl.xsi
"/usr/bin/perl" "/usr/share/perl5/core_perl/ExtUtils/xsubpp" -typemap "/usr/share/perl5/core_perl/ExtUtils/typemap" -typemap "typemap" Perl.xs > Perl.xsc && mv Perl.xsc Perl.c
cc -c -D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Os -fomit-frame-pointer -DVERSION=\"1.636\" -DXS_VERSION=\"1.636\" -fPIC "-I/usr/lib/perl5/core_perl/CORE" -W -Wall -Wpointer-arith -Wbad-function-cast -Wno-comment -Wno-sign-compare -Wno-cast-qual -Wmissing-noreturn -Wno-unused-parameter Perl.c
In file included from Perl.xs:7:0:
DBIXS.h:22:20: fatal error: EXTERN.h: No such file or directory
compilation terminated.
Makefile:625: recipe for target 'Perl.o' failed
make: *** [Perl.o] Error 1
TIMB/DBI-1.636.tar.gz
/usr/bin/make -- NOT OK
What can I do to resolve it?
Works with Ubuntu 14.04 after install make gcc
You need the libperl headers to be able to build certain modules, including DBI. On Alpine it looks like they are provided by the package perl-dev.
From http://www.perlmonks.org/bare/?node_id=486526
EXTERN.h is part of the perl C API which is needed for embedding the interpreter and building XS modules. The official perl distribution contains all these files, but many linux distributions don't bundle it as part of the base perl package (some even leave out a lot of core modules). There should be one or more additional packages for your distribution that supply the C API files. They're usually called "perl-dev" or something like it. (From googling, it looks like the mandrage package is "perl-devel-5.*.rpm")
So the solution looked like to add perl-dev to the apk add command, but this was not enough:
In file included from DBIXS.h:23:0,
from Perl.xs:7:
/usr/lib/perl5/core_perl/CORE/perl.h:699:23: fatal error: sys/types.h: No such file or directory
compilation terminated.
Makefile:628: recipe for target 'Perl.o' failed
Ok, some more googling resulted in addin musl-dev as well. Now that works:
FROM alpine
ENV MHA_NODE_VERSION=0.54 \
MHA_MANAGER_VERSION=0.55
COPY ./mha/* /tmp/
# mha4mysql-manager-0.55.tar.gz
# mha4mysql-node-0.54.tar.gz
RUN apk add --update perl perl-dev musl-dev make gcc \
&& perl -MCPAN -e 'install DBD::mysql' \
&& perl -MCPAN -e "install Config::Tiny" \
&& perl -MCPAN -e "install Log::Dispatch" \
&& perl -MCPAN -e "install Parallel::ForkManager" \
&& cd /tmp \
&& tar -zxf mha4mysql-node-${MHA_NODE_VERSION}.tar.gz \
&& cd mha4mysql-node-${MHA_NODE_VERSION}/ \
&& perl Makefile.PL \
&& make \
&& make install \
&& cd /tmp \
&& tar -zxf mha4mysql-manager-${MHA_MANAGER_VERSION}.tar.gz \
&& cd mha4mysql-manager-${MHA_MANAGER_VERSION}/ \
&& perl Makefile.PL \
&& make \
&& make install \
&& apk del make gcc musl-dev perl-dev \
&& rm -rf /var/cache/apk/*
ENTRYPOINT ["/usr/bin/perl", "-de0"]

Building Emacs from git master complains errors in configure.ac

When I try to build Emacs from https://github.com/emacs-mirror/emacs at 4f54f7b using ./autogen.sh it errors as
Checking whether you have the necessary tools...
(Read INSTALL.REPO for more details on building Emacs)
Checking for autoconf (need at least version 2.65)...
ok
Checking for automake (need at least version 1.11)...
ok
Your system has the required tools.
Running 'autoreconf -fi -I m4' ...
configure.ac:54: error: possibly undefined macro: AS_ECHO
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
configure.ac:95: error: possibly undefined macro: AM_INIT_AUTOMAKE
configure.ac:245: error: possibly undefined macro: AC_DEFINE
configure.ac:752: error: possibly undefined macro: AM_PROG_CC_C_O
configure.ac:763: error: possibly undefined macro: AM_CONDITIONAL
configure.ac:1020: error: possibly undefined macro: AM_SUBST_NOTMAKE
configure.ac:1471: error: possibly undefined macro: m4_default
autoreconf: /usr/bin/autoconf failed with exit status: 1
I've tried the common tricks to solve it without success. What to do?
Update: make bootstrap fails as
cd . && ACLOCAL_PATH='' /bin/bash /home/per/Work/emacs/build-aux/missing aclocal-1.14 -I m4
if [ -x ./config.status ]; then \
./config.status --recheck; \
else \
./configure --cache-file=/dev/null; \
fi
cd . && /bin/bash /home/per/Work/emacs/build-aux/missing automake-1.14 --gnu -a -c lib/Makefile
[ -r "src/config.in" ] || ( cd . && /bin/bash /home/per/Work/emacs/build-aux/missing autoheader )
running CONFIG_SHELL=/bin/bash /bin/bash ./configure --prefix=/home/per/opt/x86_64-unknown-linux-gnu/emacs-snapshot CFLAGS=-O2 PKG_CONFIG_PATH=/home/per/opt/x86_64-unknown-linux-gnu/fish-snapshot/share/pkgconfig:/home/per/opt/x86_64-unknown-linux-gnu/sparsehash-2.0.2/lib/pkgconfig:/home/per/opt/x86_64-unknown-linux-gnu/igraph-0.6/lib/pkgconfig:/home/per/opt/x86_64-unknown-linux-gnu/libarchive-snapshot/lib/pkgconfig:/home/per/opt/x86_64-unknown-linux-gnu/libgit2-snapshot/lib/pkgconfig:/home/per/opt/x86_64-unknown-linux-gnu/nettle-3.0/lib/pkgconfig: --no-create --no-recursion
checking for xcrun... no
checking for GNU Make... make
./configure: line 2853: syntax error near unexpected token `1.11'
./configure: line 2853: `AM_INIT_AUTOMAKE(1.11)'
Makefile:412: receptet för målet ”config.status” misslyckades
make: *** [config.status] Fel 2