Haskell static linking using the stack on Amazon Linux for use on AWS Lambda

I am trying to create a statically linked Haskell hello world program on an EC2 instance in order to run it on AWS Lambda.

My only change to the "simple" stack.yaml file:

ghc-options:
    "*": -static -optc-static -optl-static -optl-pthread

First I got the following errors:

[ec2-user@ip-172-31-0-238 lambdatest]$ stack build
lambdatest-0.1.0.0: configure
Configuring lambdatest-0.1.0.0...
lambdatest-0.1.0.0: build
Preprocessing executable 'lambdatest' for lambdatest-0.1.0.0...
Linking .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/lambdatest/lambdatest ...
/usr/bin/ld: cannot find -lgmp
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lrt
/usr/bin/ld: cannot find -ldl
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status

The first thing I tried was to install gmp-devel:

[ec2-user@ip-172-31-0-238 lambdatest]$ sudo yum install gmp-devel.x86_64
Loaded plugins: priorities, update-motd, upgrade-helper
Package gmp-devel-6.0.0-11.16.amzn1.x86_64 already installed and latest version
Nothing to do

but it doesn't seem like a problem.

Next, I installed glibc-static and gmp-static, and now I see the following message:

[ec2-user@ip-172-31-0-238 lambdatest]$ stack build
lambdatest-0.1.0.0: build
Preprocessing executable 'lambdatest' for lambdatest-0.1.0.0...
Linking .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/lambdatest/lambdatest ...
/home/ec2-user/.stack/programs/x86_64-linux/ghc-7.10.2/lib/ghc-7.10.2/rts/libHSrts.a(Linker.o): In function `internal_dlopen':

Could not resolve file /home/ben/ghc-7.10.2/rts/Linker.c

But when I run the identical "stack build" command a second time, it completes without errors.

+4
source share
1 answer

So that worked for me:

fpcomplete:

curl -sSL https://s3.amazonaws.com/download.fpcomplete.com/centos/7/fpco.repo | \
sudo tee /etc/yum.repos.d/fpco.repo

:

sudo yum -y install stack

ghc:

stack setup

:

stack new lambdatest simple

stack.yaml :

ghc-options:
    "*": -static -optc-static -optl-static -optl-pthread

:

sudo yum install glibc-static
sudo yum install gmp-static

stack build !

EC2, AWS Lambda Node.js.

+4

Source: https://habr.com/ru/post/1622833/


All Articles