kcl icon indicating copy to clipboard operation
kcl copied to clipboard

Provide Statically Linked Binaries

Open MattHodge opened this issue 4 months ago • 3 comments

Feature Request

Is your feature request related to a problem? Please describe:

I had to spend a fair amount of time trying to get kcl installed into a docker container, even a simple ubuntu:22.04 image.

The following images are all built and tested using the following commands:

  • Build: docker build --platform linux/amd64 -t kcl-test:latest .
  • Test: docker run kcl-test:latest

Attempt 1:

FROM ubuntu:22.04

RUN apt-get update && apt-get install -y --no-install-recommends \
  bash \
  curl \
  ca-certificates

ARG KCL_VERSION="v0.7.5"
ARG KCL_PLATFORM="linux-amd64"
RUN set -x && \
  mkdir -p /tmp/kclvm && \
  cd /tmp/kclvm && \
  curl --retry 5 --retry-connrefused -LO https://github.com/kcl-lang/kcl/releases/download/${KCL_VERSION}/kclvm-${KCL_VERSION}-${KCL_PLATFORM}.tar.gz && \
  tar -zxvf kclvm-${KCL_VERSION}-${KCL_PLATFORM}.tar.gz && \
  mv kclvm/bin/* /usr/local/bin && \
  chmod +x /usr/local/bin/kcl && \
  chmod +x /usr/local/bin/kclvm_cli && \
  rm -rf /tmp/kclvm

RUN echo 'foo = "bar"' > /tmp/foo.k
ENTRYPOINT [ "kcl", "/tmp/foo.k" ]

Error raised:

Error: run linker failed: stdout , stderr:

After a while I ended up reading the installation FAQ which told me I need gcc

Attempt 2 - Adding gcc

FROM ubuntu:22.04

RUN apt-get update && apt-get install -y --no-install-recommends \
  bash \
  curl \
  ca-certificates \
  gcc

ARG KCL_VERSION="v0.7.5"
ARG KCL_PLATFORM="linux-amd64"
RUN set -x && \
  mkdir -p /tmp/kclvm && \
  cd /tmp/kclvm && \
  curl --retry 5 --retry-connrefused -LO https://github.com/kcl-lang/kcl/releases/download/${KCL_VERSION}/kclvm-${KCL_VERSION}-${KCL_PLATFORM}.tar.gz && \
  tar -zxvf kclvm-${KCL_VERSION}-${KCL_PLATFORM}.tar.gz && \
  mv kclvm/bin/* /usr/local/bin && \
  chmod +x /usr/local/bin/kcl && \
  chmod +x /usr/local/bin/kclvm_cli && \
  rm -rf /tmp/kclvm

RUN echo 'foo = "bar"' > /tmp/foo.k
ENTRYPOINT [ "kcl", "/tmp/foo.k" ]

Error raised:

Error: run linker failed: stdout , stderr: /usr/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status

Attempt 3- Adding gcc-multilib:

FROM ubuntu:22.04

RUN apt-get update && apt-get install -y --no-install-recommends \
  bash \
  curl \
  ca-certificates \
  gcc \
  gcc-multilib

ARG KCL_VERSION="v0.7.5"
ARG KCL_PLATFORM="linux-amd64"
RUN set -x && \
  mkdir -p /tmp/kclvm && \
  cd /tmp/kclvm && \
  curl --retry 5 --retry-connrefused -LO https://github.com/kcl-lang/kcl/releases/download/${KCL_VERSION}/kclvm-${KCL_VERSION}-${KCL_PLATFORM}.tar.gz && \
  tar -zxvf kclvm-${KCL_VERSION}-${KCL_PLATFORM}.tar.gz && \
  mv kclvm/bin/* /usr/local/bin && \
  chmod +x /usr/local/bin/kcl && \
  chmod +x /usr/local/bin/kclvm_cli && \
  rm -rf /tmp/kclvm

RUN echo 'foo = "bar"' > /tmp/foo.k
ENTRYPOINT [ "kcl", "/tmp/foo.k" ]

🥳 This works:

foo: bar

Describe the feature you'd like:

I would like if the binaries were all statically linked so I didn't need to have any dependencies installed in my operating system for kcl to work.

MattHodge avatar Mar 03 '24 08:03 MattHodge