mirror of https://github.com/mattn/go-sqlite3.git
Add description to cross compile for specific libc dependency
Can be used to compile for raspberry 4 (rasbian bullseye for example)
This commit is contained in:
parent
846fea6c14
commit
b9f760a2b3
44
README.md
44
README.md
|
@ -35,6 +35,8 @@ This package follows the official [Golang Release Policy](https://golang.org/doc
|
||||||
- [Android](#android)
|
- [Android](#android)
|
||||||
- [ARM](#arm)
|
- [ARM](#arm)
|
||||||
- [Cross Compile](#cross-compile)
|
- [Cross Compile](#cross-compile)
|
||||||
|
- [Cross Compiling from macOS](#cross-compiling-from-macos)
|
||||||
|
- [Cross Compile for specific libc version](#cross-compile-for-specific-libc-version)
|
||||||
- [Google Cloud Platform](#google-cloud-platform)
|
- [Google Cloud Platform](#google-cloud-platform)
|
||||||
- [Linux](#linux)
|
- [Linux](#linux)
|
||||||
- [Alpine](#alpine)
|
- [Alpine](#alpine)
|
||||||
|
@ -228,6 +230,48 @@ Steps:
|
||||||
|
|
||||||
Please refer to the project's [README](https://github.com/FiloSottile/homebrew-musl-cross#readme) for further information.
|
Please refer to the project's [README](https://github.com/FiloSottile/homebrew-musl-cross#readme) for further information.
|
||||||
|
|
||||||
|
## Cross Compile for specific libc version
|
||||||
|
|
||||||
|
If you need to cross compile and the remote machine uses an older libc version, then you can use a simple Dockerfile (see below) to create a matching image and compile using docker
|
||||||
|
|
||||||
|
```dockerfile
|
||||||
|
# Dockerfile to compile your go application
|
||||||
|
# with the libc version 2.31-13 as used by debian:bullseye or on Raspbian (Raspberry 4 bullseye)
|
||||||
|
|
||||||
|
# check your libs version using `ldd --version` and download the matching golang image if needed
|
||||||
|
FROM golang:1.23-bullseye AS build
|
||||||
|
|
||||||
|
RUN echo $(ldd --version)
|
||||||
|
|
||||||
|
# Install cross-compilation tools
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
gcc-arm-linux-gnueabihf \
|
||||||
|
g++-arm-linux-gnueabihf \
|
||||||
|
libc6-dev-arm64-cross \
|
||||||
|
libsqlite3-dev \
|
||||||
|
sqlite3
|
||||||
|
|
||||||
|
# Set environment variables for cross-compilation
|
||||||
|
ENV GOARM=7
|
||||||
|
ENV GOARCH=arm
|
||||||
|
ENV GOOS=linux
|
||||||
|
ENV CGO_ENABLED=1
|
||||||
|
ENV CC=arm-linux-gnueabihf-gcc
|
||||||
|
ENV CXX=arm-linux-gnueabihf-g++
|
||||||
|
|
||||||
|
# Set the working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Default command: compile the file specified by the argument
|
||||||
|
ENTRYPOINT ["sh", "-c", "go build -buildvcs=false -o myapp"]
|
||||||
|
|
||||||
|
# build image using
|
||||||
|
# docker build -t myapp-arm64 .
|
||||||
|
|
||||||
|
# compile your go code with
|
||||||
|
# docker run --rm -v $(pwd):/app myapp-arm64
|
||||||
|
```
|
||||||
|
|
||||||
# Google Cloud Platform
|
# Google Cloud Platform
|
||||||
|
|
||||||
Building on GCP is not possible because Google Cloud Platform does not allow `gcc` to be executed.
|
Building on GCP is not possible because Google Cloud Platform does not allow `gcc` to be executed.
|
||||||
|
|
Loading…
Reference in New Issue