-
Notifications
You must be signed in to change notification settings - Fork 484
build: add cross compile docker #1156
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b1a4479
build: add cross compile docker
discord9 3d9b075
build: added compile python to github action
discord9 585469f
fix: correct path
discord9 e00c206
fix: Python Compile
discord9 9c0b4b0
fix: run mulitple cmds
discord9 2dd1e13
fix: both cross compile docker file&github action
discord9 33e576d
refactor: compile-python.sh
discord9 6e322b1
chore: put wget install together
discord9 fe482b9
fix: CR advices
discord9 fc54f04
chore: add `-F pyo3_backend`
discord9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| FROM ubuntu:22.04 as builder | ||
|
|
||
| ENV LANG en_US.utf8 | ||
| WORKDIR /greptimedb | ||
|
|
||
| # Install dependencies. | ||
| RUN apt-get update && apt-get install -y \ | ||
| libssl-dev \ | ||
| protobuf-compiler \ | ||
| curl \ | ||
| build-essential \ | ||
| pkg-config \ | ||
| wget | ||
|
|
||
| # Install Rust. | ||
| SHELL ["/bin/bash", "-c"] | ||
| RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y | ||
| ENV PATH /root/.cargo/bin/:$PATH | ||
|
|
||
| # Install cross platform toolchain | ||
| RUN apt-get -y update && \ | ||
| apt-get -y install libssl-dev pkg-config g++-aarch64-linux-gnu gcc-aarch64-linux-gnu && \ | ||
| apt-get install binutils-aarch64-linux-gnu | ||
|
|
||
| COPY . . | ||
| # This three env var is set in script, so I set it manually in dockerfile. | ||
| ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/ | ||
| ENV LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib/ | ||
| ENV PY_INSTALL_PATH=${PWD}/python_arm64_build | ||
| RUN chmod +x ./docker/aarch64/compile-python.sh && \ | ||
| ./docker/aarch64/compile-python.sh | ||
| # Install rustup target for cross compiling. | ||
| RUN rustup target add aarch64-unknown-linux-gnu | ||
| # Set the environment variable for cross compiling and compile it | ||
| # Build the project in release mode. Set Net fetch with git cli to true to avoid git error. | ||
| RUN export PYO3_CROSS_LIB_DIR=$PY_INSTALL_PATH/lib && \ | ||
| alias python=python3 && \ | ||
| CARGO_NET_GIT_FETCH_WITH_CLI=1 && \ | ||
| cargo build --target aarch64-unknown-linux-gnu --release | ||
|
waynexia marked this conversation as resolved.
Outdated
|
||
|
|
||
| # Exporting the binary to the clean image | ||
| FROM ubuntu:22.04 as base | ||
|
|
||
| RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install ca-certificates | ||
|
|
||
| WORKDIR /greptime | ||
| COPY --from=builder /greptimedb/target/aarch64-unknown-linux-gnu/release/greptime /greptime/bin/ | ||
| ENV PATH /greptime/bin/:$PATH | ||
|
|
||
| ENTRYPOINT ["greptime"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # this script will download Python source code, compile it, and install it to /usr/local/lib | ||
| # then use this python to compile cross-compiled python for aarch64 | ||
|
|
||
| wget https://www.python.org/ftp/python/3.10.10/Python-3.10.10.tgz | ||
| tar -xvf Python-3.10.10.tgz | ||
| cd Python-3.10.10 | ||
| # explain Python compile options here a bit:s | ||
| # --enable-shared: enable building a shared Python library (default is no) but we do need it for calling from rust | ||
| # CC, CXX, AR, LD, RANLIB: set the compiler, archiver, linker, and ranlib programs to use | ||
| # build: the machine you are building on, host: the machine you will run the compiled program on | ||
| # --with-system-ffi: build _ctypes module using an installed ffi library, see Doc/library/ctypes.rst, not used in here TODO: could remove | ||
| # ac_cv_pthread_is_default=no ac_cv_pthread=yes ac_cv_cxx_thread=yes: | ||
| # allow cross-compiled python to have -pthread set for CXX, see https://github.com/python/cpython/pull/22525 | ||
| # ac_cv_have_long_long_format=yes: target platform supports long long type | ||
| # disable-ipv6: disable ipv6 support, we don't need it in here | ||
| # ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no: disable pty support, we don't need it in here | ||
|
|
||
| # Build local python first, then build cross-compiled python. | ||
| ./configure \ | ||
| --enable-shared \ | ||
| ac_cv_pthread_is_default=no ac_cv_pthread=yes ac_cv_cxx_thread=yes \ | ||
| ac_cv_have_long_long_format=yes \ | ||
| --disable-ipv6 ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no && \ | ||
| make | ||
| make install | ||
| cd .. | ||
| export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/ | ||
| export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib/ | ||
| export PY_INSTALL_PATH=${PWD}/python_arm64_build | ||
| cd Python-3.10.10 && \ | ||
| make clean && \ | ||
| make distclean && \ | ||
| alias python=python3 && \ | ||
| ./configure --build=x86_64-linux-gnu --host=aarch64-linux-gnu \ | ||
| --prefix=$PY_INSTALL_PATH --enable-optimizations \ | ||
| CC=aarch64-linux-gnu-gcc \ | ||
| CXX=aarch64-linux-gnu-g++ \ | ||
| AR=aarch64-linux-gnu-ar \ | ||
| LD=aarch64-linux-gnu-ld \ | ||
| RANLIB=aarch64-linux-gnu-ranlib \ | ||
| --enable-shared \ | ||
| ac_cv_pthread_is_default=no ac_cv_pthread=yes ac_cv_cxx_thread=yes \ | ||
| ac_cv_have_long_long_format=yes \ | ||
| --disable-ipv6 ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no && \ | ||
| make && make altinstall && \ | ||
| cd .. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.