Skip to content

Commit

Permalink
Adds python. Closes compiler-explorer/python-builder#3 (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgodbolt authored Nov 25, 2024
1 parent f454e54 commit 47a2b72
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- lc3
- misc
- nasm
- python
- pythran
- rocm
- rust-cg-gcc
Expand Down
22 changes: 22 additions & 0 deletions Dockerfile.python
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ubuntu:20.04

# Enable source repositories so we can use `apt build-dep` to get all the
# build dependencies for Python 3.5+.
RUN sed -i -- 's/#deb-src/deb-src/g' /etc/apt/sources.list && \
sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list

ARG DEBIAN_FRONTEND=noninteractive
RUN apt update -y -q && apt upgrade -y -q && apt update -y -q && \
apt -q build-dep -y python3.8 && \
apt -q install -y \
curl \
git \
libssl-dev \
unzip \
xz-utils

RUN mkdir -p /root
COPY python /root/
COPY common.sh /root/

WORKDIR /root
41 changes: 41 additions & 0 deletions python/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

set -exu
source common.sh

ROOT=$(pwd)
VERSION=$1
FULLNAME=python-${VERSION}
OUTPUT=${ROOT}/${FULLNAME}.tar.xz
LAST_REVISION="${3:-}"

if [[ -d "${2}" ]]; then
OUTPUT=$2/${FULLNAME}.tar.xz
else
OUTPUT=${2-$OUTPUT}
fi

REVISION="python-${VERSION}"
initialise "${REVISION}" "${OUTPUT}" "${LAST_REVISION}"

DEST=/root/built

curl -sL https://www.python.org/ftp/python/${VERSION}/Python-${VERSION}.tgz | tar zxf -
pushd Python-${VERSION}
./configure \
--prefix=${DEST} \
--enable-optimizations \
--without-pymalloc

make -j$(nproc)
make install
popd

# strip executables
find ${DEST} -type f -perm /u+x -exec strip -d {} \;

# delete tests and static libraries to save disk space
find ${DEST} -type d -name test -exec rm -rf {} +
find ${DEST} -type f -name *.a -delete

complete "${DEST}" "${FULLNAME}" "${OUTPUT}"

0 comments on commit 47a2b72

Please sign in to comment.