Giter Site home page Giter Site logo

fastdroid / kotlin-native-cross-toolchains Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shengyun-zhou/llvm-cross-toolchains

0.0 0.0 0.0 311 KB

Easily build-tools for kotlin/native. (wait...)

Shell 36.59% C++ 0.35% Python 13.77% C 46.46% CMake 2.79% Batchfile 0.05%

kotlin-native-cross-toolchains's Introduction

LLVM Cross Toolchain

A cross toolchain collection based on LLVM with multi architecture and platform support.

Supported target platforms:

  • Linux: musl-libc, glibc

  • Android

  • Windows: MinGW, MSVC(Experiment), Cygwin

  • Darwin: MacOSX, Mac-Catalyst, iOS, tvOS, watchOS

  • BSD: FreeBSD

  • WebAssembly(WASM): Emscripten, WAMR(with custom extensions)

The toolchain itself works on Linux, Windows and MacOSX now.

Build

1. Prerequisite tools and libs

  • GCC >= 8

  • CMake >= 3.15

  • Ninja

    It can be installed via pip:

    pip install ninja
  • Python 3 and related python packages:

    Python >= 3.8 is required on Windows to support unelevated symlinks with developer mode

    pip install zstandard
    
  • Some development libs:

Lib CentOS Ubuntu/Debian
libz zlib-devel zlib1g-dev
liblzma xz-devel liblzma-dev
libxml2 libxml2-devel libxml2-dev
  • Windows host:

    • MSYS2

    NOTE: To build in MSYS2, you can install the following packages with pacman:

    curl rsync make patch
    mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja mingw-w64-x86_64-python3 mingw-w64-x86_64-zlib mingw-w64-x86_64-xz mingw-w64-x86_64-libxml2 mingw-w64-x86_64-polly
    
    • Windows subsystem for Linux(WSL) with any Linux distribution(Optional)

2. Configure project

The file version contains the versions of some important toolchain components, such as glibc, musl-libc and so on.

The array variable CROSS_TARGETS in the file cross-targets defines all cross target triples to be built.

You can change version and cross-targets based on your need.

3. Prepare stuff

(1) Linux kernel header

NOTE for MacOSX host: Linux kernel header must be built on Linux environment, it's recommended to build in Docker Linux image.

prebuilt-linux-header/build-linux-header.sh
(2) Linux glibc

NOTE: glibc must be built in glibc based Linux environment(eg. CentOS, Debian, Ubuntu).

Prerequisite development libs:

Lib CentOS Ubuntu/Debian
libgmp gmp-devel libgmp-dev
libmpfr mpfr-devel libmpfr-dev
libmpc libmpc-devel libmpc-dev
# Build glibc from source, it will take a long time
prebuilt-glibc/build-glibc.sh
(3) Android Bionic libc

Prerequisite: Android NDK >= r21e

# Set the installation path of Android NDK
export ANDROID_NDK_HOME=/path/to/android-ndk
# Extract Bionic headers and libs from NDK
prebuilt-bionic/extract_bionic_from_ndk.sh
(4) Darwin SDKs

Method 1: (recommended)extract SDKs from installed XCode on MacOSX host

  1. Install gnu-tar, it can be installed via homebrew:

    brew install gnu-tar

    Check if command gtar is available.

  2. Execute tool:

    prebuilt-darwin-sdk/extract_sdks_from_xcode.sh
  3. Check and modify values of MACOSX_VERSION, IOS_VERSION, APPLE_TVOS_VERSION, APPLE_WATCHOS_VERSION in the file version to match those in XCode.

Method 2: package SDKs manually

  1. Download SDKs from Internet or follow here to package SDKs manually.

    Known download sources(may be invalid):

  2. Create .tar.xz package for each SDK and rename them by name formats:

    • MacOSX${MACOS_VERSION}.sdk.tar.xz (for example, MacOSX11.3.sdk.tar.xz)
    • iPhoneOS${IOS_VERSION}.sdk.tar.xz, iPhoneSimulator${IOS_VERSION}.sdk.tar.xz
    • AppleTVOS${APPLE_TVOS_VERSION}.sdk.tar.xz, AppleTVSimulator${APPLE_TVOS_VERSION}.sdk.tar.xz
    • WatchOS${APPLE_WATCHOS_VERSION}.sdk.tar.xz, WatchSimulator${APPLE_WATCHOS_VERSION}.sdk.tar.xz
  3. Put SDK packages in directory prebuilt-darwin-sdk.

(5) Apple cctools

NOTE for Windows host: cctools must be built in WSL.

Prerequisite:

  • clang >= 4
  • development libs:
Lib CentOS Ubuntu/Debian
llvm llvm-devel llvm-dev
llvm(static libs) llvm-static llvm-dev
libuuid libuuid-devel uuid-dev
openssl openssl-devel libssl-dev

Check if the following command works first:

llvm-config --link-static --libs lto

Build cctools:

./prebuilt-cctools/build-cctools.sh
(6) MSVC
  1. Enter Visual Studio Developer Command Prompt first, then enter MSYS2/Cygwin shell.
  2. Execute the shell script:
./prebuilt-msvc-sdk/extract_sdk_from_msvc.sh
(7) Cygwin
./prebuilt-cygwin/prepare_sysroot.sh
(8) MSYS2
./prebuilt-msys2/prepare_sysroot.sh
(9) FreeBSD
./prebuilt-freebsd/prepare_sysroot.sh

4. Build and Assemble toolchain

Execute the script build-all.sh to start building.

./build-all.sh

The output directory path is defined by variable OUTPUT_DIR in the file config.

After building has finished successfully, you can use tool strip_toolchain.sh to strip the output toolchain.

Project Reference

kotlin-native-cross-toolchains's People

Contributors

shengyun-zhou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.