kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.61k stars 113 forks source link

Provide Statically Linked Binaries #1100

Closed MattHodge closed 2 months ago

MattHodge commented 7 months ago

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:

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.

Peefy commented 7 months ago

Hello! Thank you for the feedback. We have the official built docker image kcllang/kcl. Have you tried it or used it as a basic mirror to construct other KCL ecosystem tools? Besides, the dockerfile is here: https://github.com/kcl-lang/cli/blob/main/Dockerfile

This is also what we are striving to do, removing the operating system compiler dependency from KCL.

MattHodge commented 7 months ago

Thanks for the quick reply @Peefy :)

The plan was to use KCL in a docker container used in CI, so was trying to make it reasonably small.

At least I have it working now! The static linking would allow for usage in images like scratch to keep them as light as possible. I'll just roll with the larger images for now.

Peefy commented 3 months ago

We have introduced an experimental feature gate in kcl v0.9.0-rc.1

You can quickly run your code by opening it through the env var KCL_FAST_EVAL=1 without the gcc and gcc-multilib deps. Welcome to try it out. ❤️