Skip to content
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

[WIP] Build via CMake #88

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@
/bnf/rust.tab.h
/bnf/rust.output
/bnf/test.bin

# CMake build folder
build/
32 changes: 22 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,36 @@ matrix:
- g++-6
- zlib1g-dev
- valgrind
- ninja-build
- git

# OSX
- os: osx
allow_failures:
- os: osx

install:
# Build mrustc
- make RUSTCSRC
- make -j 2
- make -C tools/minicargo
#install:
# Build mrustc
#- make RUSTCSRC
#- make -j 2
#- make -C tools/minicargo

script:
- set -e
- make -f minicargo.mk output/libtest.hir # libstd
- make test # hello_world
- git status
# - set -e
- mkdir build
- cd build
- cmake ..
- make mrustc -j4
- make minicargo -j4
# - make rust_standard_libs -j4

# Test
# - make -f minicargo.mk output/libtest.hir # libstd
# - make test # hello_world
# Tests
- set +e
- make local_tests -k
# - set +e
# - make local_tests -k
# - CC=gcc-6 make rust_tests -k
# rustc (DISABLED: llvm build)
# - make -f minicargo.mk output/rustc
Expand Down
122 changes: 122 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
project(mrustc)
cmake_minimum_required(VERSION 3.4)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(ExternalProject)
include(GatherGitInfo)

# - [x] Find exact rustc version to be downloaded
# - [x] Download rustc-source
# - [ ] Unpack to some location
# - [ ] Original makefile patches rustc-source? Find out why and whether that's needed!


###############################################################################
# Cache Variables #
###############################################################################

set(MRUSTC_RUSTC_VERSION
"1.19.0"
CACHE STRING
"Version of rustc to expect. Must match the downloaded sourcecode!")

set(MRUSTC_RUSTC_CHANNEL
"stable"
CACHE STRING
"Channel of rustc to expect. Can be 'stable' or 'nightly'.
Must match the downloaded sourcecode!")

set(MRUSTC_RUSTC_SOURCE_URL
"https://static.rust-lang.org/dist/rustc-1.19.0-src.tar.gz"
CACHE STRING
"URL or local path of where rustc's source should be downloaded from.
This can also be a local file!")

set(MRUSTC_RUSTC_SOURCE_HASH
"SHA256=15231f5053fb72ad82be91f5abfd6aa60cb7898c5089e4f1ac5910a731090c51"
CACHE STRING
"SHA256 of the file downloaded from MRUSTC_RUSTC_SOURCE_URL.
You can leave this empty to skip verifying whether the downloaded archive is correct.")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

#############################################################################
# Download rustc-source #
#############################################################################

# Specify where to put or to find the rustc sources
set(RUSTC_SOURCE_DIR ${CMAKE_BINARY_DIR}/rustc-source)

ExternalProject_Add(get_rustc_source
SOURCE_DIR ${CMAKE_BINARY_DIR}/rustc-source
URL ${MRUSTC_RUSTC_SOURCE_URL}
URL_HASH ${MRUSTC_RUSTC_SOURCE_HASH}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)

###############################################################################
# Compile Tools (Minicargo, ...) #
###############################################################################
add_subdirectory(tools/common)
add_subdirectory(tools/minicargo)
add_subdirectory(tools/standalone_miri)
add_subdirectory(tools/testrunner)


###############################################################################
# Compile mrustc #
###############################################################################

gather_git_info()
string(TIMESTAMP BUILD_TIMESTAMP UTC)
message(STATUS "Git status: ${GIT_IS_DIRTY}")
message(STATUS "Git ref...: ${GIT_HEAD_REF}")
message(STATUS "Git hash..: ${GIT_HEAD_HASH}")
message(STATUS "Git shash.: ${GIT_HEAD_HASH_SHORT}")
message(STATUS "Git branch: ${GIT_BRANCH}")
message(STATUS "Buildtime.: ${BUILD_TIMESTAMP}")

add_subdirectory(src)

###############################################################################
# Build Rust Libraries #
###############################################################################

build_rust_std_lib(
TARGET rust_libstd
CRATE_TO_BUILD ${RUSTC_SOURCE_DIR}/src/libstd
DEPENDS get_rustc_source)

build_rust_std_lib(
TARGET rust_libpanic_unwind
CRATE_TO_BUILD ${RUSTC_SOURCE_DIR}/src/libpanic_unwind
DEPENDS get_rustc_source)

build_rust_std_lib(
TARGET rust_libtest
CRATE_TO_BUILD ${RUSTC_SOURCE_DIR}/src/libtest
DEPENDS get_rustc_source)

build_rust_std_lib(
TARGET rust_libgetopts
CRATE_TO_BUILD ${RUSTC_SOURCE_DIR}/src/libgetopts
DEPENDS get_rustc_source rust_libpanic_unwind)

# FIXME: Fails with: EXCEPTION: Unable to find a manifest for log:^0.3.0
# build_rust_std_lib(
# TARGET rust_libproc_macro
# CRATE_TO_BUILD ${RUSTC_SOURCE_DIR}/src/libproc_macro
# DEPENDS get_rustc_source)

add_custom_target(rust_standard_libs ALL
DEPENDS
rust_libstd
rust_libpanic_unwind
rust_libtest
rust_libgetopts
# rust_libproc_macro
)
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ Windows
- Open `vsproject/mrustc.sln` and build minicargo
- Run `vsproject/build_rustc_minicargo.cmd` to attempt to build libstd

CMake
-----

> This is Work-In-Progress and has only been tested on Linux so far!

From the directoy where you cloned or extracted *mrustc*:

```sh
mkdir build
cd build
cmake ..
make mrustc
make minicargo
```

Building non-rustc code
=======================
Expand Down
34 changes: 34 additions & 0 deletions cmake/GatherGitInfo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
include(GetGitRevisionDescription)

#! gather_git_info : Populates variables with the current commit hash, branch, ...
#
# Defines the following variables:
#
# GIT_IS_DIRTY - Truthful if there are uncommited changes
# GIT_HEAD_REF - Head ref., eg. "refs/head/master"
# GIT_HEAD_HASH - HEADs commit hash (long)
# GIT_HEAD_HASH_SHORT - HEADs commit hash (short - 7 chars)
# GIT_BRANCH - Current branch
#
function(gather_git_info)
git_local_changes(GIT_IS_DIRTY)
get_git_head_revision(GIT_HEAD_REF GIT_HEAD_HASH "--pretty=%h") # Get short hash

string(SUBSTRING ${GIT_HEAD_HASH} 0 7 GIT_HEAD_HASH_SHORT)

if (${GIT_HEAD_REF})
string(REPLACE "/" ";" GIT_HEAD_REF_AS_LIST ${GIT_HEAD_REF}) # Split eg. refs/head/master
list(REVERSE GIT_HEAD_REF_AS_LIST)
list(GET GIT_HEAD_REF_AS_LIST 0 GIT_BRANCH)
else()
# Might be detached from HEAD
set(GIT_BRANCH "unknown")
set(GIT_HEAD_REF "unknown")
endif()

set(GIT_IS_DIRTY ${GIT_IS_DIRTY} PARENT_SCOPE)
set(GIT_HEAD_REF ${GIT_HEAD_REF} PARENT_SCOPE)
set(GIT_HEAD_HASH ${GIT_HEAD_HASH} PARENT_SCOPE)
set(GIT_HEAD_HASH_SHORT ${GIT_HEAD_HASH_SHORT} PARENT_SCOPE)
set(GIT_BRANCH ${GIT_BRANCH} PARENT_SCOPE)
endfunction()
Loading