Skip to content
This repository has been archived by the owner on May 2, 2021. It is now read-only.

Commit

Permalink
Switch to Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnimuc committed Jun 30, 2019
1 parent b264213 commit 89c99ed
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 121 deletions.
134 changes: 30 additions & 104 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,115 +4,41 @@ This is an experimental repo for exploring how to upgrade Cxx.jl's building syst
## Usage
Pre-built binaries can be found in the release page: https://github.com/Gnimuc/CxxBuilder/releases

### Build for Linux-x86_64
1. Download Julia-v1.1 binary: https://julialang-s3.julialang.org/bin/linux/x64/1.1/julia-1.1.0-linux-x86_64.tar.gz
2. Unzip downloaded tarball, create a directory called `JuliaBinary` and move unzipped contents into it
3. Download Julia-v1.1 source: https://github.com/JuliaLang/julia/releases/download/v1.1.0/julia-1.1.0.tar.gz
4. Unzip downloaded tarball, create a directory called `JuliaSource` and move unzipped contents into it
5. Download LLVM binary: https://github.com/staticfloat/LLVMBuilder/releases/download/v6.0.1-4%2Bnowasm/LLVM.v6.0.1.x86_64-linux-gnu-gcc7.tar.gz
6. Create a directory called `LLVM` and move downloaded tarball into it
7. Now, the file hierarchy should look like this:
### Build for Linux-x86_64(gcc7)
1. Edit build_tarballs.jl
2. Replace corresponding source URL=>SHA pairs with:
```
CxxBuilder +
| libcxxffi
| patches
| build_tarballs.jl
| README.md
+ JuliaBinary +
| juliabin +
| bin
| etc
| include
| lib
| ...
+ JuliaSource +
| julia +
| base
| contrib
| deps
| doc
| etc
| ...
+ LLVM +
| LLVM.v6.0.1.x86_64-linux-gnu-gcc7.tar.gz
# julia binary
"https://github.com/Gnimuc/JuliaBuilder/releases/download/v1.1.1/julia-1.1.1-x86_64-linux-gnu-gcc7.tar.gz" =>
"???",
# LLVM binary
"https://github.com/staticfloat/LLVMBuilder/releases/download/v6.0.1-5%2Bnowasm/LLVM.v6.0.1.x86_64-linux-gnu-gcc7.tar.gz" =>
"6fca2fedc5ae4ead8b2fd62d863e2a556075d4d7de8b8c66cc8feeea6dc33851",
```
8. Run `julia --color=yes build_tarballs.jl --verbose --debug x86_64-linux-gnu-gcc7`
9. Find the binary in the `products` folder
3. Run `julia --color=yes build_tarballs.jl --verbose --debug x86_64-linux-gnu-gcc7`

### Build for MacOS
1. Download Julia-v1.1 binary: https://julialang-s3.julialang.org/bin/mac/x64/1.1/julia-1.1.0-mac64.dmg
2. Open the dmg image, right-click Julia-1.1.app, click `Show Package Contents`⁩, copy `⁨Contents⁩/⁨Resources/julia`⁩ to a new directory called `JuliaBinary`
3. Download Julia-v1.1 source: https://github.com/JuliaLang/julia/releases/download/v1.1.0/julia-1.1.0.tar.gz
4. Unzip downloaded tarball, create a directory called `JuliaSource` and move unzipped contents into it
5. Download LLVM binary: https://github.com/staticfloat/LLVMBuilder/releases/download/v6.0.1-4%2Bnowasm/LLVM.v6.0.1.x86_64-apple-darwin14-gcc7.tar.gz
6. Create a directory called `LLVM` and move downloaded tarball into it
7. Now, the file hierarchy should look like this:
### Build for MacOS(gcc7)
1. Edit build_tarballs.jl
2. Replace corresponding source URL=>SHA pairs with:
```
CxxBuilder +
| libcxxffi
| patches
| build_tarballs.jl
| README.md
+ JuliaBinary +
| juliabin +
| bin
| etc
| include
| lib
| ...
+ JuliaSource +
| julia +
| base
| contrib
| deps
| doc
| etc
| ...
+ LLVM +
| LLVM.v6.0.1.x86_64-apple-darwin14-gcc7.tar.gz
# julia binary
"https://github.com/Gnimuc/JuliaBuilder/releases/download/v1.1.1/julia-1.1.1-x86_64-apple-darwin14.tar.gz" =>
"c41d6535bc57bb0f96f69b3c44fdc169ec98dd780f8845f65a4d0bb65a4900ee",
# LLVM binary
"https://github.com/staticfloat/LLVMBuilder/releases/download/v6.0.1-5%2Bnowasm/LLVM.v6.0.1.x86_64-apple-darwin14-gcc7.tar.gz" =>
"12ea772128b9f9306188fd9933ad5c26a247e598578fffd6487d6dc4eb417ec8",
```
8. Run `julia --color=yes build_tarballs.jl --verbose --debug x86_64-apple-darwin14-gcc7`
9. Find the binary in the `products` folder
3. Run `julia --color=yes build_tarballs.jl --verbose --debug x86_64-apple-darwin14-gcc7`

### Build for Windows-x86_64
1. Download Julia-v1.1 binary: https://julialang-s3.julialang.org/bin/winnt/x64/1.1/julia-1.1.1-win64.exe
2. Install it on a Windows machine, move those installed files into a folder called `juliabin`⁩, create a new directory called `JuliaBinary` on your Linux machine that runs BB2 and move `juliabin`⁩ into it
3. Download Julia-v1.1 source: https://github.com/JuliaLang/julia/releases/download/v1.1.0/julia-1.1.0.tar.gz
4. Unzip downloaded tarball, create a directory called `JuliaSource` and move unzipped contents into it
5. Download LLVM binary: https://github.com/staticfloat/LLVMBuilder/releases/download/v6.0.1-4%2Bnowasm/LLVM.v6.0.1.x86_64-w64-mingw32-gcc7.tar.gz
6. Create a directory called `LLVM` and move downloaded tarball into it
7. Download dlfcn-win32 v1.2.0 source code from https://github.com/dlfcn-win32/dlfcn-win32/archive/v1.2.0.zip
8. Unzip downloaded tarball, create a directory called `dlfcn` and move unzipped code into it
9. Now, the file hierarchy should look like this:
### Build for Windows-x86_64(gcc7)
1. Edit build_tarballs.jl
2. Replace corresponding source URL=>SHA pairs with:
```
CxxBuilder +
| libcxxffi
| patches
| build_tarballs.jl
| README.md
+ dlfcn +
| dlfcn-win32 +
| cmake-test
| visual-studio
| CMakeLists.txt
| ...
+ JuliaBinary +
| juliabin +
| bin
| etc
| include
| lib
| ...
+ JuliaSource +
| julia +
| base
| contrib
| deps
| doc
| etc
| ...
+ LLVM +
| LLVM.v6.0.1.x86_64-w64-mingw32-gcc7.tar.gz
# julia binary
"https://github.com/Gnimuc/JuliaBuilder/releases/download/v1.1.1/julia-1.1.1-x86_64-w64-mingw32.tar.gz" =>
"9446377e8fd7b143f2ed1ea7ec6470d25e463b89828b728b226d9e221e5506a5",
# LLVM binary
"https://github.com/staticfloat/LLVMBuilder/releases/download/v6.0.1-5%2Bnowasm/LLVM.v6.0.1.x86_64-w64-mingw32-gcc7.tar.gz" =>
"998a1932884121f15d7d5b2e75fb977695a4d448dd3888c10a18aafa83faf8c9",
```
10. Run `julia --color=yes build_tarballs.jl --verbose --debug x86_64-w64-mingw32-gcc7`
11. Find the binary in the `products` folder
3. Run `julia --color=yes build_tarballs.jl --verbose --debug x86_64-w64-mingw32-gcc7`
31 changes: 21 additions & 10 deletions build_tarballs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ for f in $WORKSPACE/srcdir/llvm_patches/*.patch; do
done
"""

# Next, we will Bash recipe for building across all platforms
# Next, build libcxxffi
script = script_setup * raw"""
# build libcxxffi
cd $WORKSPACE/srcdir/
Expand All @@ -94,16 +94,25 @@ if [[ ${target} == *mingw32* ]]; then
make install VERBOSE=1
fi
cd $WORKSPACE/srcdir/
mkdir build && cd build
CMAKE_FLAGS="-DCMAKE_INSTALL_PREFIX=$prefix -DCMAKE_TOOLCHAIN_FILE=/opt/$target/$target.toolchain"
CMAKE_FLAGS="${CMAKE_FLAGS} -DJULIA_SOURCE_PREFIX=$WORKSPACE/srcdir/julia-1.1.1"
CMAKE_FLAGS="${CMAKE_FLAGS} -DJULIA_BINARY_PREFIX=$WORKSPACE/srcdir/juliabin"
CMAKE_FLAGS="${CMAKE_FLAGS} -DLLVMBUILDER_PREFIX=$WORKSPACE/srcdir"
cmake .. ${CMAKE_FLAGS}
make -j${nproc} VERBOSE=1
make install VERBOSE=1
# use CMake on all platforms except Windows
if [[ "${target}" == *linux* ]] || [[ "${target}" == *apple* ]] || [[ "${target}" == *freebsd* ]]; then
mkdir build && cd build
CMAKE_FLAGS="-DCMAKE_INSTALL_PREFIX=$prefix -DCMAKE_TOOLCHAIN_FILE=/opt/$target/$target.toolchain"
CMAKE_FLAGS="${CMAKE_FLAGS} -DJULIA_SOURCE_PREFIX=$WORKSPACE/srcdir/julia-1.1.1"
CMAKE_FLAGS="${CMAKE_FLAGS} -DJULIA_BINARY_PREFIX=$WORKSPACE/srcdir/juliabin"
CMAKE_FLAGS="${CMAKE_FLAGS} -DLLVMBUILDER_PREFIX=$WORKSPACE/srcdir"
cmake .. ${CMAKE_FLAGS}
make -j${nproc} VERBOSE=1
make install VERBOSE=1
fi
# use Make on Windows
if [[ ${target} == *mingw32* ]]; then
make -j${nproc} VERBOSE=1 -f Windows.Makefile JULIA_SOURCE_PREFIX=$WORKSPACE/srcdir/julia-1.1.1 JULIA_BINARY_PREFIX=$WORKSPACE/srcdir/juliabin LLVMBUILDER_PREFIX=$WORKSPACE/srcdir
make install VERBOSE=1
fi
# copy LLVM/Clang assets
mkdir -p ${prefix}/src/clang-6.0.1/include
mkdir -p ${prefix}/src/llvm-6.0.1/include
mkdir -p ${prefix}/build/clang-6.0.1/lib/clang/6.0.1/include
Expand All @@ -116,10 +125,12 @@ cp -r $WORKSPACE/srcdir/lib/* ${prefix}/lib/
cp -r $WORKSPACE/srcdir/lib/clang/6.0.1/include/* ${prefix}/build/clang-6.0.1/lib/clang/6.0.1/include/
cp -r ${prefix}/build/llvm-6.0.1/include/* ${prefix}/build/clang-6.0.1/include/
# generate clang_constants.jl
cd $WORKSPACE/srcdir
make -f GenerateConstants.Makefile BASE_LLVM_BIN=$WORKSPACE/srcdir BASE_JULIA_BIN=$WORKSPACE/srcdir/juliabin BASE_JULIA_SRC=$WORKSPACE/srcdir/julia LLVM_VERSION=6.0.1
cp $WORKSPACE/srcdir/clang_constants.jl ${prefix}/build/
# copy mingw headers
if [[ ${target} == *mingw32* ]] && [[ ${nbits} == 64 ]]; then
cp -r $WORKSPACE/srcdir/bin/* ${prefix}/bin
mkdir -p ${prefix}/mingw/include
Expand Down
13 changes: 6 additions & 7 deletions libcxxffi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
cmake_minimum_required(VERSION 3.8.0)
project(cxxjl)

if(WIN32)
message(FATAL_ERROR "Binary-build for Windows using CMake is NOT supported, please use `Windows.Makefile` instead.")
endif()

if(JULIA_SOURCE_PREFIX)
set(JULIA_SOURCE_INCLUDE_DIRS ${JULIA_SOURCE_PREFIX}/src/support)
message(STATUS "JULIA_SOURCE_INCLUDE_DIRS: " ${JULIA_SOURCE_INCLUDE_DIRS})
Expand Down Expand Up @@ -54,7 +58,7 @@ if(WIN32)
message(STATUS "CMAKE_DL_LIBS: " ${CMAKE_DL_LIBS})
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti")

set(CXXJL_TARGET cxxffi)

Expand All @@ -63,7 +67,7 @@ link_directories(${CLANG_LIB_DIRS} ${JULIA_LIB_DIRS})
add_library(${CXXJL_TARGET} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/bootstrap.cpp)

target_include_directories(${CXXJL_TARGET} PUBLIC ${CLANG_INCLUDE_DIRS} ${CLANG_SOURCE_INCLUDE_DIRS} ${JULIA_INCLUDE_DIRS} ${JULIA_SOURCE_INCLUDE_DIRS})
target_compile_options(${CXXJL_TARGET} PUBLIC -DLLVM_NDEBUG -DLIBRARY_EXPORTS -fno-rtti)
target_compile_options(${CXXJL_TARGET} PUBLIC -DLLVM_NDEBUG -DLIBRARY_EXPORTS)

set(CLANG_LIBS clangFrontendTool
clangBasic
Expand Down Expand Up @@ -97,11 +101,6 @@ message(STATUS "LLVM_LIBS: " ${LLVM_LIBS})
if(APPLE)
target_link_libraries(${CXXJL_TARGET} ${JULIA_LIBS} ${LLVM_LIBS})
target_link_libraries(${CXXJL_TARGET} -Xlinker -all_load ${CLANG_LIBS})
elseif(WIN32)
target_link_libraries(${CXXJL_TARGET} ${JULIA_LIBS} ${LLVM_LIBS})
target_link_libraries(${CXXJL_TARGET} ${CMAKE_DL_LIBS})
target_link_libraries(${CXXJL_TARGET} -Wl,--whole-archive ${CLANG_LIBS} -Wl,--no-whole-archive -lversion)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS true)
else()
target_link_libraries(${CXXJL_TARGET} ${JULIA_LIBS} ${LLVM_LIBS})
target_link_libraries(${CXXJL_TARGET} -Wl,--whole-archive ${CLANG_LIBS} -Wl,--no-whole-archive)
Expand Down
48 changes: 48 additions & 0 deletions libcxxffi/Windows.Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
JULIA_SOURCE_INCLUDE_DIRS := $(JULIA_SOURCE_PREFIX)/src/support

JULIA_INCLUDE_DIRS := $(JULIA_BINARY_PREFIX)/include/julia
CLANG_SOURCE_INCLUDE_DIRS := /workspace/srcdir/llvm-6.0.1.src/tools/clang/include
CLANG_SOURCE_INCLUDE_DIRS += /workspace/srcdir/llvm-6.0.1.src/tools/clang/lib
CLANG_INCLUDE_DIRS := $(LLVMBUILDER_PREFIX)/include

JULIA_LIBS := $(JULIA_BINARY_PREFIX)/bin/libjulia.dll
LLVM_LIBS := $(JULIA_BINARY_PREFIX)/bin/LLVM.dll

JULIA_LIB_DIRS := $(JULIA_BINARY_PREFIX)/bin
JULIA_LIB_DIRS += $(JULIA_BINARY_PREFIX)/lib
JULIA_LIB_DIRS += $(JULIA_BINARY_PREFIX)/lib/julia
CLANG_LIB_DIRS := $(LLVMBUILDER_PREFIX)/lib

LIB_DIRS := $(JULIA_LIB_DIRS) $(CLANG_LIB_DIRS)
LIBS = $(addprefix -L,$(LIB_DIRS))

CLANG_LIBS := clangFrontendTool clangBasic clangLex clangDriver clangFrontend clangParse
CLANG_LIBS += clangAST clangASTMatchers clangSema clangAnalysis clangEdit
CLANG_LIBS += clangRewriteFrontend clangRewrite clangSerialization clangStaticAnalyzerCheckers
CLANG_LIBS += clangStaticAnalyzerCore clangStaticAnalyzerFrontend clangTooling clangToolingCore
CLANG_LIBS += clangCodeGen clangARCMigrate clangFormat
LINKED_LIBS = $(addprefix -l,$(CLANG_LIBS))

INCLUDE_DIRS := $(JULIA_SOURCE_INCLUDE_DIRS) $(JULIA_INCLUDE_DIRS) $(CLANG_SOURCE_INCLUDE_DIRS) $(CLANG_INCLUDE_DIRS)
INCLUDES = $(addprefix -I,$(INCLUDE_DIRS))

DEFS := -DLLVM_NDEBUG -DLIBRARY_EXPORTS
FLAGS = -std=c++11 -fno-rtti -fPIC -O0 -g

all: usr/lib/libcxxffi.dll

build:
@mkdir -p $(CURDIR)/build

build/bootstrap.o: bootstrap.cpp $(LIB_DEPENDENCY) | build
$(CXX) $(DEFS) $(FLAGS) $(INCLUDES) -c bootstrap.cpp -o $@

build/libcxxffi.dll: build/bootstrap.o $(LIB_DEPENDENCY) | build
$(CXX) -shared -fPIC $(LIBS) -l$(JULIA_LIBS) -l$(LLVM_LIBS) -o $@ -Wl,--whole-archive $(LINKED_LIBS) -Wl,--no-whole-archive $< -lversion

destdir/bin:
@mkdir -p /workspace/destdir/bin

install: build/libcxxffi.dll
cp -f $(CURDIR)/build/bootstrap.o /workspace/destdir/bin/
cp -f $(CURDIR)/build/libcxxffi.dll /workspace/destdir/bin/

0 comments on commit 89c99ed

Please sign in to comment.