Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using submodules for GDB & Static Python #18

Merged
merged 5 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install dependencies
run: sudo apt-get install -y wget
Expand Down
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[submodule "cpython-static"]
path = src/submodule_packages/cpython-static
url = git@github.com:guyush1/cpython-static.git
roddyrap marked this conversation as resolved.
Show resolved Hide resolved
branch = python3.12-static
[submodule "binutils-gdb-static"]
path = src/submodule_packages/binutils-gdb
url = git@github.com:guyush1/binutils-gdb.git
branch = gdb-static
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ FROM ubuntu:24.04

# Install dependencies
RUN apt update && apt install -y \
bison \
file \
flex \
g++ \
g++-aarch64-linux-gnu \
g++-arm-linux-gnueabi \
Expand All @@ -14,10 +17,14 @@ RUN apt update && apt install -y \
gcc-mips-linux-gnu \
gcc-mipsel-linux-gnu \
gcc-powerpc-linux-gnu \
git \
libncurses-dev \
m4 \
make \
patch \
pkg-config \
python3.12 \
libpython3-dev \
texinfo \
wget \
xz-utils
Expand Down
31 changes: 17 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
ARCHS := x86_64 arm aarch64 powerpc mips mipsel
TARGETS := $(addprefix build-, $(ARCHS))
PACK_TARGETS := $(addprefix pack-, $(ARCHS))
SUBMODULE_PACKAGES := $(wildcard src/submodule_packages/*)
BUILD_PACKAGES_DIR := "build/packages"

.PHONY: clean help download_packages build patch-gdb build-docker-image $(TARGETS) $(PACK_TARGETS)
.PHONY: clean help download_packages build build-docker-image $(TARGETS) $(PACK_TARGETS)

help:
@echo "Usage:"
Expand All @@ -23,30 +25,28 @@ build/build-docker-image.stamp: Dockerfile

build-docker-image: build/build-docker-image.stamp

build/download-packages.stamp: build/build-docker-image.stamp src/download_packages.sh
mkdir -p build/packages
build/download-packages.stamp: build/build-docker-image.stamp src/compilation/download_packages.sh
mkdir -p $(BUILD_PACKAGES_DIR)
docker run --user $(shell id -u):$(shell id -g) \
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
/app/gdb/src/download_packages.sh /app/gdb/build/packages
/app/gdb/src/compilation/download_packages.sh /app/gdb/$(BUILD_PACKAGES_DIR)/
touch build/download-packages.stamp

download-packages: build/download-packages.stamp
build/symlink-git-packages.stamp: $(SUBMODULE_PACKAGES)
roddyrap marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p $(BUILD_PACKAGES_DIR)
ln -sf $(addprefix /app/gdb/, $(SUBMODULE_PACKAGES)) $(BUILD_PACKAGES_DIR)/

build/patch-gdb.stamp: build/build-docker-image.stamp src/gdb_static.patch build/download-packages.stamp
docker run --user $(shell id -u):$(shell id -g) \
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
/app/gdb/src/patch_gdb.sh /app/gdb/build/packages/gdb /app/gdb/src/gdb_static.patch
touch build/patch-gdb.stamp
symlink-git-packages: build/symlink-git-packages.stamp

patch-gdb: build/patch-gdb.stamp
download-packages: build/download-packages.stamp

build: $(TARGETS)

$(TARGETS): build-%: download-packages patch-gdb build-docker-image
$(TARGETS): build-%: symlink-git-packages download-packages build-docker-image
mkdir -p build
docker run --user $(shell id -u):$(shell id -g) \
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
/app/gdb/src/build.sh $* /app/gdb/build/ /app/gdb/src/gdb_static.patch
/app/gdb/src/compilation/build.sh $* /app/gdb/build/ /app/gdb/src

pack: $(PACK_TARGETS)

Expand All @@ -55,7 +55,10 @@ $(PACK_TARGETS): pack-%: build-%
tar -czf "build/artifacts/gdb-static-$*.tar.gz" -C "build/artifacts/$*" .; \
fi

clean:
clean-git-packages:
git submodule foreach '[[ ! "$$sm_path" == src/submodule_packages/* ]] || git clean -xffd'

clean: clean-git-packages
rm -rf build
# Kill and remove all containers of image gdb-static
docker ps -a | grep -P "^[a-f0-9]+\s+gdb-static\s+" | awk '{print $$1}' | xargs docker rm -f 2>/dev/null || true
Expand Down
90 changes: 79 additions & 11 deletions src/build.sh → src/compilation/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

# Include utils library
script_dir=$(dirname "$0")
. "$script_dir/utils.sh"
source "$script_dir/utils.sh"
roddyrap marked this conversation as resolved.
Show resolved Hide resolved

# Don't want random unknown things to fail in the build procecss!
set -e

function set_compliation_variables() {
# Set compilation variables such as which compiler to use.
Expand Down Expand Up @@ -208,6 +211,64 @@ function build_ncurses() {
popd > /dev/null
}

function build_python() {
# Build python.
#
# Parameters:
# $1: python package directory
# $2: target architecture
#
# Echoes:
# The python build directory
#
# Returns:
# 0: success
# 1: failure
local python_dir="$1"
local target_arch="$2"
local python_lib_dir="$(realpath "$python_dir/build-$target_arch")"

echo "$python_lib_dir"
roddyrap marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p "$python_lib_dir"

# Having a python-config file is an indication that we successfully built python.
if [[ -f "$python_lib_dir/python-config" ]]; then
>&2 echo "Skipping build: libpython already built for $target_arch"
return 0
fi

pushd "$python_lib_dir" > /dev/null
>&2 fancy_title "Building python for $target_arch"

export LINKFORSHARED=" "
export MODULE_BUILDTYPE="static"
export CONFIG_SITE="$python_dir/config.site-static"
>&2 CFLAGS="-static" LDFLAGS="-static" ../configure \
--prefix=$(realpath .) \
--disable-test-modules \
--with-ensurepip=no \
--without-decimal-contextvar \
--build=x86_64-pc-linux-gnu \
--host=$HOST \
--with-build-python=/usr/bin/python3.12 \
--disable-ipv6 \
--disable-shared

>&2 make -j $(nproc)
if [[ $? -ne 0 ]]; then
return 1
fi

# Install python (in build dir using the prefix set above), in order to have a bash (for cross-compilation) python3-config that works.
>&2 make install
if [[ $? -ne 0 ]]; then
return 1
fi

>&2 fancy_title "Finished building python for $target_arch"
popd > /dev/null
}

function build_libmpfr() {
# Build libmpfr.
#
Expand Down Expand Up @@ -298,7 +359,8 @@ function build_gdb() {

>&2 fancy_title "Building gdb for $target_arch"

../configure --enable-static --enable-tui --with-static-standard-libraries --disable-inprocess-agent \
../configure -C --enable-static --with-static-standard-libraries --disable-inprocess-agent \
--enable-tui --with-python=/app/gdb/build/packages/cpython-static/build-$target_arch/bin/python3-config \
"--with-libiconv-prefix=$libiconv_prefix" --with-libiconv-type=static \
"--with-gmp=$libgmp_prefix" \
"--with-mpfr=$libmpfr_prefix" \
Expand Down Expand Up @@ -395,9 +457,11 @@ function build_gdb_with_dependencies() {
# Parameters:
# $1: target architecture
# $2: build directory
# $3: src directory

local target_arch="$1"
local build_dir="$2"
local source_dir="$3"
local packages_dir="$build_dir/packages"
local artifacts_dir="$build_dir/artifacts"

Expand Down Expand Up @@ -427,27 +491,31 @@ function build_gdb_with_dependencies() {
if [[ $? -ne 0 ]]; then
return 1
fi

set_ncurses_link_variables "$ncursesw_build_dir"

build_and_install_gdb "$packages_dir/gdb" \
"$iconv_build_dir/lib/.libs/" \
"$gmp_build_dir/.libs/" \
"$mpfr_build_dir/src/.libs/" \
"$artifacts_dir" \
"$target_arch"
python_build_dir="$(build_python "$packages_dir/cpython-static" "$target_arch")"
if [[ $? -ne 0 ]]; then
return 1
fi

build_and_install_gdb "$packages_dir/binutils-gdb" \
"$iconv_build_dir/lib/.libs/" \
"$gmp_build_dir/.libs/" \
"$mpfr_build_dir/src/.libs/" \
"$artifacts_dir" \
"$target_arch"
if [[ $? -ne 0 ]]; then
return 1
fi
}

function main() {
if [[ $# -ne 3 ]]; then
>&2 echo "Usage: $0 <target_arch> <build_dir>"
>&2 echo "Usage: $0 <target_arch> <build_dir> <src_dir>"
exit 1
fi

build_gdb_with_dependencies "$1" "$2"
build_gdb_with_dependencies "$1" "$2" "$3"
if [[ $? -ne 0 ]]; then
>&2 echo "Error: failed to build gdb with dependencies"
exit 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

# Include utils library
script_dir=$(dirname "$0")
. "$script_dir/utils.sh"
source "$script_dir/utils.sh"

# List of package URLs to download
PACKAGE_URLS=(
SOURCE_URLS=(
roddyrap marked this conversation as resolved.
Show resolved Hide resolved
"https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.17.tar.gz"
"https://ftp.gnu.org/pub/gnu/gmp/gmp-6.3.0.tar.xz"
"https://ftp.gnu.org/pub/gnu/mpfr/mpfr-4.2.1.tar.xz"
"https://ftp.gnu.org/gnu/gdb/gdb-15.2.tar.xz"
"https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.5.tar.gz"
)

Expand Down Expand Up @@ -188,7 +187,7 @@ function download_gdb_packages() {

fancy_title "Starting download of GDB packages"

for url in "${PACKAGE_URLS[@]}"; do
for url in "${SOURCE_URLS[@]}"; do
package_dir=$(package_url_to_dir "$url")
download_and_extract_package "$url" "$package_dir" &
download_pids+=($!)
Expand All @@ -203,7 +202,6 @@ function download_gdb_packages() {
done

fancy_title "Finished downloading GDB packages"

popd
}

Expand Down
File renamed without changes.
70 changes: 0 additions & 70 deletions src/gdb_static.patch

This file was deleted.

Loading
Loading