Skip to content

loonystarzz/crossforge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CrossForge - Multi-Architecture Native Compilation Tool

CrossForge is a native compilation tool that uses Docker containers to compile C projects for multiple architectures. It performs native compilation within Docker containers of different architectures, providing a unified interface for building across platforms.

Features

  • Native compilation for 9 different architectures using Docker containers
  • Static linking support with --static flag
  • Automatic dependency management via Docker containers
  • Universal binary processing - works with any C/C++ project
  • Docker-based isolation - clean build environments

Supported Architectures

  • amd64 - Intel x86 64-bit
  • i386 - Intel x86 32-bit
  • arm32v5 - ARM 32-bit (ARMv5)
  • arm32v7 - ARM 32-bit (ARMv7)
  • arm64v8 - ARM 64-bit (ARMv8)
  • mips64le - MIPS 64-bit (little-endian)
  • ppc64le - PowerPC 64-bit (little-endian)
  • riscv64 - RISC-V 64-bit
  • s390x - IBM System/390 64-bit

Prerequisites

  • Docker installed and running
  • GCC compiler (for building xforge itself)
  • Make (optional, for using the Makefile)

Building

Using Make (recommended)

make

Manual compilation

gcc -Wall -Wextra -std=c99 -O2 -o crossforge xforge.c

Installation

System-wide installation

sudo ./install.sh

This installs to /opt/archbox/ with a symlink in /usr/local/bin/.

Local use

Simply place the crossforge binary in your project root directory or add it to your PATH.

Usage

Basic Syntax

./crossforge -a <architecture> [--static] <command>

Dynamic Linking (default)

Natively compile a project for ARM using ARM container:

./crossforge -a arm32v7 make -C project/

Natively compile for RISC-V 64-bit using RISC-V container:

./crossforge -a riscv64 make -C myproject/

Static Linking

Create fully static binaries that run anywhere:

./crossforge -a s390x --static make -C project/

Natively compile with static linking and custom make targets:

./crossforge -a arm64v8 --static make -C project/ clean all

Compile a single static binary:

./crossforge -a amd64 --static gcc -o test test.c

Building Docker Images

First build the Docker images for your target architectures:

# Build all architectures
./build-docker-images.sh

# Build specific architecture
./build-docker-images.sh -a s390x

# Clean existing images before building
./build-docker-images.sh --cleanup

How It Works

Dynamic Builds

  1. Architecture Detection: CrossForge maps the specified architecture to the appropriate Docker image and platform.
  2. Docker Management: It automatically pulls the required Docker image if not already available.
  3. Container Execution: Runs the specified command in a Docker container with the current directory mounted as /workspace.
  4. Native Compilation: The Docker container contains the native compilation toolchain for that architecture.

Static Builds (--static)

  1. Normal Build: First builds the project normally in the target architecture container.
  2. Binary Detection: Automatically finds all executable ELF binaries in the project directory.
  3. Static Conversion: Uses staticx to convert each binary to a fully static version (adds -static suffix).
  4. Dependency Bundling: All library dependencies are bundled into the binary.

Docker Images

CrossForge uses custom Debian-based Docker images with staticx pre-installed:

  • crossforge-amd64:latest for x86_64
  • crossforge-s390x:latest for s390x
  • crossforge-riscv64:latest for RISC-V
  • crossforge-arm32v7:latest for ARM 32-bit
  • crossforge-arm64v8:latest for ARM 64-bit
  • And more... (one per supported architecture)

Each image includes:

  • Complete native compilation toolchain for that architecture
  • Development libraries and headers
  • Staticx for creating static binaries
  • Patchelf for ELF manipulation

Static vs Dynamic Binaries

Dynamic Binaries (default)

  • Smaller size - libraries are shared
  • Requires target system libraries - glibc, libcurl, etc.
  • Faster build times - no static conversion step

Static Binaries (--static)

  • Self-contained - no external dependencies
  • Larger size - all libraries bundled
  • Portable - runs on any system of target architecture
  • Slower build - additional staticx conversion step

Environment Variables

The tool runs commands in Docker containers with the current working directory mounted as /workspace. All environment variables from the host system are available in the container.

Error Handling

  • If an unsupported architecture is specified, the tool lists all supported architectures.
  • If Docker is not available or fails to pull an image, appropriate error messages are displayed.
  • Command execution failures are reported with exit codes.
  • Staticx failures show clear error messages with troubleshooting hints.

Troubleshooting

Docker not running

Ensure Docker is installed and running:

docker --version
docker info

Permission denied

If you get permission errors, you may need to run Docker commands with sudo or add your user to the docker group:

sudo usermod -aG docker $USER

Architecture not supported

Check the list of supported architectures:

./crossforge

Build failures

Ensure your project's Makefile and source code are compatible with native compilation in different architectures. Some projects may require additional configuration or patches for certain architectures.

Static conversion fails

Check that:

  • Docker images have staticx installed
  • Built binaries are ELF executables
  • Sufficient disk space for static binaries

Examples

Complete Workflow

# 1. Build Docker images
./build-docker-images.sh -a s390x

# 2. Natively compile with static linking
./crossforge -a s390x --static make -C myproject/

# 3. Deploy static binary
scp myproject/binary-static user@target-system:/usr/local/bin/

Multiple Architectures

# Build for multiple architectures
for arch in amd64 arm64v8 s390x; do
    ./crossforge -a $arch --static make -C project/
done

# Results: project/binary-static (per arch)

Cleaning

Remove built files:

make clean

Clean Docker images:

./build-docker-images.sh --cleanup

Uninstall from system:

make uninstall

License

This project is provided as-is for educational and development purposes.

About

simple compilation for many architectures

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors