From e939561265e709540cc7c2c306746daf741c4896 Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Sun, 21 Oct 2018 14:46:25 +0200 Subject: [PATCH 01/15] CMake: Building all cpp binaries using cmake and download rustc-source using cmake --- CMakeLists.txt | 131 ++++++++++++++++++ cmake/GetGitRevisionDescription.cmake | 168 +++++++++++++++++++++++ cmake/GetGitRevisionDescription.cmake.in | 41 ++++++ src/CMakeLists.txt | 51 +++++++ src/ast/CMakeLists.txt | 21 +++ src/expand/CMakeLists.txt | 23 ++++ src/hir/CMakeLists.txt | 43 ++++++ src/hir_conv/CMakeLists.txt | 9 ++ src/hir_expand/CMakeLists.txt | 10 ++ src/hir_typeck/CMakeLists.txt | 18 +++ src/include/CMakeLists.txt | 2 + src/macro_rules/CMakeLists.txt | 9 ++ src/mir/CMakeLists.txt | 22 +++ src/parse/CMakeLists.txt | 24 ++++ src/resolve/CMakeLists.txt | 7 + src/trans/CMakeLists.txt | 22 +++ tools/common/CMakeLists.txt | 23 ++++ tools/minicargo/CMakeLists.txt | 26 ++++ tools/standalone_miri/CMakeLists.txt | 42 ++++++ tools/testrunner/CMakeLists.txt | 17 +++ 20 files changed, 709 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/GetGitRevisionDescription.cmake create mode 100644 cmake/GetGitRevisionDescription.cmake.in create mode 100644 src/CMakeLists.txt create mode 100644 src/ast/CMakeLists.txt create mode 100644 src/expand/CMakeLists.txt create mode 100644 src/hir/CMakeLists.txt create mode 100644 src/hir_conv/CMakeLists.txt create mode 100644 src/hir_expand/CMakeLists.txt create mode 100644 src/hir_typeck/CMakeLists.txt create mode 100644 src/include/CMakeLists.txt create mode 100644 src/macro_rules/CMakeLists.txt create mode 100644 src/mir/CMakeLists.txt create mode 100644 src/parse/CMakeLists.txt create mode 100644 src/resolve/CMakeLists.txt create mode 100644 src/trans/CMakeLists.txt create mode 100644 tools/common/CMakeLists.txt create mode 100644 tools/minicargo/CMakeLists.txt create mode 100644 tools/standalone_miri/CMakeLists.txt create mode 100644 tools/testrunner/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..b94db695e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,131 @@ +project(mrustc) +cmake_minimum_required(VERSION 3.4) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +include(ExternalProject) +include(GetGitRevisionDescription) + +# - [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_SOURCE_URL + "https://github.com/rust-lang/rust/archive/1.19.0.tar.gz" + CACHE STRING + "URL or local path of where rustc's source should be downloaded from. ") + +set(MRUSTC_RUSTC_SOURCE_HASH + "SHA256=7e1ecb476118b79b5abed02bc7a724bb65413057e26f1d2b8538c572f7463be0" + 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.") + + +############################################################################# +# Download rustc-source # +############################################################################# + + +#! download_rustc_source : Downloads the rustc-source from the location specified inside +# MRUSTC_RUSTC_SOURCE_URL +# +# Defines ${TARGET}_DIRECTORY. +# +# \param:TARGET Set the name of the target which will trigger the download. +# \group:DEPENDS List of targets the download should depend upon +# +function(download_rustc_source) + set(options "") + set(oneValueArgs TARGET ) + set(multiValueArgs DEPENDS) + cmake_parse_arguments(DL_RUSTC + "${options}" + "${oneValueArgs}" + "${multiValueArgs}" + ${ARGN}) + + if (NOT MRUSTC_RUSTC_SOURCE_URL) + message(FATAL_ERROR "MRUSTC_RUSTC_SOURCE_URL is not set! Please specify where the rustc-sources are!") + endif() + + if (NOT DL_RUSTC_TARGET) + message(FATAL_ERROR "TARGET property of download_rustc_source must be set!") + endif() + + set(${DL_RUSTC_TARGET}_DIRECTORY ${CMAKE_BINARY_DIR}/rustc-source PARENT_SCOPE) + + ExternalProject_Add(${DL_RUSTC_TARGET} + PREFIX ${${DL_RUSTC_TARGET}_DIRECTORY} + URL ${MRUSTC_RUSTC_SOURCE_URL} + URL_HASH ${MRUSTC_RUSTC_SOURCE_HASH} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + DEPENDS ${DL_RUSTC_DEPENDS}) +endfunction() + +download_rustc_source(TARGET rustc_source) +# add_dependencies(hello_world rustc_source) + +############################################################################### +# Compile Tools (Minicargo, ...) # +############################################################################### +add_subdirectory(tools/common) +add_subdirectory(tools/minicargo) +add_subdirectory(tools/standalone_miri) +add_subdirectory(tools/testrunner) + +############################################################################### +# Compile mrustc # +############################################################################### + +# Set up some meta-information +# $V$(CXX) -o $@ -c $< $(CXXFLAGS) $(CPPFLAGS) -MMD -MP -MF $@.dep +# -D VERSION_GIT_FULLHASH=\"$(shell git show --pretty=%H -s)\" +# -D VERSION_GIT_BRANCH="\"$(shell git symbolic-ref -q --short HEAD || git describe --tags --exact-match)\"" +# -D VERSION_GIT_SHORTHASH=\"$(shell git show -s --pretty=%h)\" +# -D VERSION_BUILDTIME="\"$(shell date -uR)\"" +# -D VERSION_GIT_ISDIRTY=$(shell git diff-index --quiet HEAD; echo $$?) + +#! 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) + 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) + + 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() + +gather_git_info() +string(TIMESTAMP BUILD_TIMESTAMP ) +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) diff --git a/cmake/GetGitRevisionDescription.cmake b/cmake/GetGitRevisionDescription.cmake new file mode 100644 index 000000000..8ab03bc5f --- /dev/null +++ b/cmake/GetGitRevisionDescription.cmake @@ -0,0 +1,168 @@ +# - Returns a version string from Git +# +# These functions force a re-configure on each git commit so that you can +# trust the values of the variables in your build system. +# +# get_git_head_revision( [ ...]) +# +# Returns the refspec and sha hash of the current head revision +# +# git_describe( [ ...]) +# +# Returns the results of git describe on the source tree, and adjusting +# the output so that it tests false if an error occurs. +# +# git_get_exact_tag( [ ...]) +# +# Returns the results of git describe --exact-match on the source tree, +# and adjusting the output so that it tests false if there was no exact +# matching tag. +# +# git_local_changes() +# +# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes. +# Uses the return code of "git diff-index --quiet HEAD --". +# Does not regard untracked files. +# +# Requires CMake 2.6 or newer (uses the 'function' command) +# +# Original Author: +# 2009-2010 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2009-2010. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +if(__get_git_revision_description) + return() +endif() +set(__get_git_revision_description YES) + +# We must run the following at "include" time, not at function call time, +# to find the path to this module rather than the path to a calling list file +get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) + +function(get_git_head_revision _refspecvar _hashvar) + set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories + set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") + get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) + if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) + # We have reached the root directory, we are not in git + set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + return() + endif() + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + endwhile() + # check if this is a submodule + if(NOT IS_DIRECTORY ${GIT_DIR}) + file(READ ${GIT_DIR} submodule) + string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule}) + get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) + get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE) + endif() + set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") + if(NOT EXISTS "${GIT_DATA}") + file(MAKE_DIRECTORY "${GIT_DATA}") + endif() + + if(NOT EXISTS "${GIT_DIR}/HEAD") + return() + endif() + set(HEAD_FILE "${GIT_DATA}/HEAD") + configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) + + configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" + "${GIT_DATA}/grabRef.cmake" + @ONLY) + include("${GIT_DATA}/grabRef.cmake") + + set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) + set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) +endfunction() + +function(git_describe _var) + if(NOT GIT_FOUND) + find_package(Git QUIET) + endif() + get_git_head_revision(refspec hash) + if(NOT GIT_FOUND) + set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) + return() + endif() + if(NOT hash) + set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) + return() + endif() + + # TODO sanitize + #if((${ARGN}" MATCHES "&&") OR + # (ARGN MATCHES "||") OR + # (ARGN MATCHES "\\;")) + # message("Please report the following error to the project!") + # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") + #endif() + + #message(STATUS "Arguments to execute_process: ${ARGN}") + + execute_process(COMMAND + "${GIT_EXECUTABLE}" + describe + ${hash} + ${ARGN} + WORKING_DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE + res + OUTPUT_VARIABLE + out + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT res EQUAL 0) + set(out "${out}-${res}-NOTFOUND") + endif() + + set(${_var} "${out}" PARENT_SCOPE) +endfunction() + +function(git_get_exact_tag _var) + git_describe(out --exact-match ${ARGN}) + set(${_var} "${out}" PARENT_SCOPE) +endfunction() + +function(git_local_changes _var) + if(NOT GIT_FOUND) + find_package(Git QUIET) + endif() + get_git_head_revision(refspec hash) + if(NOT GIT_FOUND) + set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) + return() + endif() + if(NOT hash) + set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) + return() + endif() + + execute_process(COMMAND + "${GIT_EXECUTABLE}" + diff-index --quiet HEAD -- + WORKING_DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE + res + OUTPUT_VARIABLE + out + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(res EQUAL 0) + set(${_var} "CLEAN" PARENT_SCOPE) + else() + set(${_var} "DIRTY" PARENT_SCOPE) + endif() +endfunction() diff --git a/cmake/GetGitRevisionDescription.cmake.in b/cmake/GetGitRevisionDescription.cmake.in new file mode 100644 index 000000000..6d8b708ef --- /dev/null +++ b/cmake/GetGitRevisionDescription.cmake.in @@ -0,0 +1,41 @@ +# +# Internal file for GetGitRevisionDescription.cmake +# +# Requires CMake 2.6 or newer (uses the 'function' command) +# +# Original Author: +# 2009-2010 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2009-2010. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +set(HEAD_HASH) + +file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024) + +string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) +if(HEAD_CONTENTS MATCHES "ref") + # named branch + string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") + if(EXISTS "@GIT_DIR@/${HEAD_REF}") + configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) + else() + configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY) + file(READ "@GIT_DATA@/packed-refs" PACKED_REFS) + if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}") + set(HEAD_HASH "${CMAKE_MATCH_1}") + endif() + endif() +else() + # detached HEAD + configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) +endif() + +if(NOT HEAD_HASH) + file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) + string(STRIP "${HEAD_HASH}" HEAD_HASH) +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..1a5ff8b49 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,51 @@ + +# Build outline for mrustc: +# +# Sourcefiles: +# Dependencies: +# Notes: Needs compiler capable of C++14 + +add_subdirectory(include) +add_subdirectory(ast) +add_subdirectory(expand) +add_subdirectory(hir) +add_subdirectory(hir_conv) +add_subdirectory(hir_expand) +add_subdirectory(hir_typeck) +add_subdirectory(macro_rules) +add_subdirectory(mir) +add_subdirectory(parse) +add_subdirectory(resolve) +add_subdirectory(trans) + +add_executable(mrustc + main.cpp + debug.cpp + ident.cpp + rc_string.cpp + span.cpp + version.cpp) + +target_link_libraries(mrustc + PRIVATE + common # tools-directory + ast + expand + hir + hir_conv + hir_expand + hir_typeck + macro_rules + mir + parse + resolve + trans + INTERFACE + include) + +target_compile_definitions(mrustc PRIVATE + -DVERSION_GIT_FULLHASH="${GIT_HEAD_HASH}" + -DVERSION_GIT_SHORTHASH="${GIT_HEAD_HASH_SHORT}" + -DVERSION_GIT_BRANCH="${GIT_BRANCH}" + -DVERSION_GIT_ISDIRTY=$ + -DVERSION_BUILDTIME="${BUILD_TIMESTAMP}") diff --git a/src/ast/CMakeLists.txt b/src/ast/CMakeLists.txt new file mode 100644 index 000000000..005e78cd7 --- /dev/null +++ b/src/ast/CMakeLists.txt @@ -0,0 +1,21 @@ +add_library(ast STATIC + "ast.cpp" + "ast.hpp" + "attrs.hpp" + "crate.cpp" + "crate.hpp" + "dump.cpp" + "expr.cpp" + "expr.hpp" + "expr_ptr.hpp" + "generics.hpp" + "item.hpp" + "macro.hpp" + "path.cpp" + "path.hpp" + "pattern.cpp" + "pattern.hpp" + "types.cpp" + "types.hpp") + +target_link_libraries(ast PUBLIC shared_includes) diff --git a/src/expand/CMakeLists.txt b/src/expand/CMakeLists.txt new file mode 100644 index 000000000..8946c5882 --- /dev/null +++ b/src/expand/CMakeLists.txt @@ -0,0 +1,23 @@ +add_library(expand STATIC + asm.cpp + cfg.cpp + cfg.hpp + concat.cpp + crate_tags.cpp + derive.cpp + env.cpp + file_line.cpp + format_args.cpp + include.cpp + lang_item.cpp + macro_rules.cpp + mod.cpp + proc_macro.cpp + proc_macro.hpp + rustc_diagnostics.cpp + std_prelude.cpp + stringify.cpp + test.cpp + test_harness.cpp) + +target_link_libraries(expand PUBLIC shared_includes) diff --git a/src/hir/CMakeLists.txt b/src/hir/CMakeLists.txt new file mode 100644 index 000000000..c4a71ab65 --- /dev/null +++ b/src/hir/CMakeLists.txt @@ -0,0 +1,43 @@ + +find_package(ZLIB REQUIRED) + + +add_library(hir STATIC + crate_post_load.cpp + crate_ptr.cpp + crate_ptr.hpp + deserialise.cpp + dump.cpp + expr.cpp + expr.hpp + expr_ptr.cpp + expr_ptr.hpp + expr_state.hpp + from_ast.cpp + from_ast_expr.cpp + from_ast.hpp + generic_params.cpp + generic_params.hpp + hir.cpp + hir.hpp + item_path.hpp + main_bindings.hpp + path.cpp + path.hpp + pattern.cpp + pattern.hpp + serialise.cpp + serialise_lowlevel.cpp + serialise_lowlevel.hpp + type.cpp + type.hpp + visitor.cpp + visitor.hpp + ) + +target_link_libraries(hir + PUBLIC + shared_includes + PRIVATE + ZLIB::ZLIB) + diff --git a/src/hir_conv/CMakeLists.txt b/src/hir_conv/CMakeLists.txt new file mode 100644 index 000000000..473bed467 --- /dev/null +++ b/src/hir_conv/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(hir_conv STATIC + bind.cpp + constant_evaluation.cpp + expand_type.cpp + main_bindings.hpp + markings.cpp + resolve_ufcs.cpp) + +target_link_libraries(hir_conv PUBLIC shared_includes) diff --git a/src/hir_expand/CMakeLists.txt b/src/hir_expand/CMakeLists.txt new file mode 100644 index 000000000..726c6507a --- /dev/null +++ b/src/hir_expand/CMakeLists.txt @@ -0,0 +1,10 @@ +add_library(hir_expand STATIC + annotate_value_usage.cpp + closures.cpp + erased_types.cpp + main_bindings.hpp + reborrow.cpp + ufcs_everything.cpp + vtable.cpp) + +target_link_libraries(hir_expand PUBLIC shared_includes) diff --git a/src/hir_typeck/CMakeLists.txt b/src/hir_typeck/CMakeLists.txt new file mode 100644 index 000000000..d8df329ee --- /dev/null +++ b/src/hir_typeck/CMakeLists.txt @@ -0,0 +1,18 @@ +add_library(hir_typeck STATIC + CMakeLists.txt + common.cpp + common.hpp + expr_check.cpp + expr_cs.cpp + expr_visit.cpp + expr_visit.hpp + helpers.cpp + helpers.hpp + impl_ref.cpp + impl_ref.hpp + main_bindings.hpp + outer.cpp + static.cpp + static.hpp) + +target_link_libraries(hir_typeck PUBLIC shared_includes) diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt new file mode 100644 index 000000000..5d1e7b7ab --- /dev/null +++ b/src/include/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(shared_includes INTERFACE) +target_include_directories(shared_includes INTERFACE . ..) diff --git a/src/macro_rules/CMakeLists.txt b/src/macro_rules/CMakeLists.txt new file mode 100644 index 000000000..7600da334 --- /dev/null +++ b/src/macro_rules/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(macro_rules STATIC + eval.cpp + macro_rules.hpp + macro_rules_ptr.hpp + mod.cpp + parse.cpp + pattern_checks.hpp) + +target_link_libraries(macro_rules PUBLIC shared_includes) diff --git a/src/mir/CMakeLists.txt b/src/mir/CMakeLists.txt new file mode 100644 index 000000000..3de7ec31f --- /dev/null +++ b/src/mir/CMakeLists.txt @@ -0,0 +1,22 @@ +add_library(mir STATIC + check.cpp + check_full.cpp + cleanup.cpp + dump.cpp + from_hir.cpp + from_hir.hpp + from_hir_match.cpp + helpers.cpp + helpers.hpp + main_bindings.hpp + mir_builder.cpp + mir.cpp + mir.hpp + mir_ptr.cpp + mir_ptr.hpp + operations.hpp + optimise.cpp + visit_crate_mir.cpp + visit_crate_mir.hpp) + +target_link_libraries(mir PUBLIC shared_includes) diff --git a/src/parse/CMakeLists.txt b/src/parse/CMakeLists.txt new file mode 100644 index 000000000..c8262af6e --- /dev/null +++ b/src/parse/CMakeLists.txt @@ -0,0 +1,24 @@ +add_library(parse STATIC + common.hpp + eTokenType.enum.h + expr.cpp + interpolated_fragment.cpp + interpolated_fragment.hpp + lex.cpp + lex.hpp + parseerror.cpp + parseerror.hpp + paths.cpp + pattern.cpp + root.cpp + token.cpp + token.hpp + tokenstream.cpp + tokenstream.hpp + tokentree.cpp + tokentree.hpp + ttstream.cpp + ttstream.hpp + types.cpp) + +target_link_libraries(parse PUBLIC shared_includes) diff --git a/src/resolve/CMakeLists.txt b/src/resolve/CMakeLists.txt new file mode 100644 index 000000000..c144d6eef --- /dev/null +++ b/src/resolve/CMakeLists.txt @@ -0,0 +1,7 @@ +add_library(resolve STATIC + absolute.cpp + index.cpp + main_bindings.hpp + use.cpp) + +target_link_libraries(resolve PUBLIC shared_includes) diff --git a/src/trans/CMakeLists.txt b/src/trans/CMakeLists.txt new file mode 100644 index 000000000..9d3bb06c0 --- /dev/null +++ b/src/trans/CMakeLists.txt @@ -0,0 +1,22 @@ +add_library(trans STATIC + allocator.cpp + allocator.hpp + codegen_c.cpp + codegen_c.hpp + codegen.cpp + codegen_c_structured.cpp + codegen.hpp + codegen_mmir.cpp + enumerate.cpp + main_bindings.hpp + mangling.cpp + mangling.hpp + monomorphise.cpp + monomorphise.hpp + target.cpp + target.hpp + trans_list.cpp + trans_list.hpp) + +target_link_libraries(trans PUBLIC shared_includes) +target_link_libraries(trans PRIVATE common) diff --git a/tools/common/CMakeLists.txt b/tools/common/CMakeLists.txt new file mode 100644 index 000000000..8cb8c257b --- /dev/null +++ b/tools/common/CMakeLists.txt @@ -0,0 +1,23 @@ + +# Build outline for common: +# +# Sourcefiles: All inside common directory +# Dependencies: None +# Notes: Needs compiler capable of C++14 + + +############################################################################### +# Compile libCommon # +############################################################################### +add_library(common STATIC + "debug.h" + "debug.cpp" + "helpers.h" + "path.h" + "path.cpp" + "target_detect.h" + "toml.h" + "toml.cpp") + +target_compile_features(common PUBLIC cxx_std_14) +target_include_directories(common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/tools/minicargo/CMakeLists.txt b/tools/minicargo/CMakeLists.txt new file mode 100644 index 000000000..5e194bdc4 --- /dev/null +++ b/tools/minicargo/CMakeLists.txt @@ -0,0 +1,26 @@ + +# Build outline for minicargo: +# +# Sourcefiles: All inside minicargo directory +# Dependencies: libCommon, threading (eg. pthread) +# Notes: Needs compiler capable of C++14 + + +############################################################################### +# Compile Minicargo # +############################################################################### +add_executable(minicargo + "build.h" + "build.cpp" + "main.cpp" + "manifest.h" + "manifest.cpp" + "repository.h" + "repository.cpp" + "stringlist.h") + +target_compile_features(minicargo PUBLIC cxx_std_14) + +find_package(Threads REQUIRED) +target_link_libraries(minicargo Threads::Threads) +target_link_libraries(minicargo common) diff --git a/tools/standalone_miri/CMakeLists.txt b/tools/standalone_miri/CMakeLists.txt new file mode 100644 index 000000000..6e73758ef --- /dev/null +++ b/tools/standalone_miri/CMakeLists.txt @@ -0,0 +1,42 @@ + +# Build outline for Standalone MIRI: +# +# Sourcefiles: All inside standalone_miri directory +# Dependencies: libCommon, threading (eg. pthread), mrustc includes +# Notes: Needs compiler capable of C++14. Disables Warnings. + + +############################################################################### +# Compile Standalone MIRI # +############################################################################### +add_executable(standalone_miri + "hir/type.hpp" + "CMakeLists.txt" + "debug.cpp" + "debug.hpp" + "hir_sim.cpp" + "hir_sim.hpp" + "lex.cpp" + "lex.hpp" + "main.cpp" + "mir.cpp" + "miri.cpp" + "miri.hpp" + "module_tree.cpp" + "module_tree.hpp" + "value.cpp" + "value.hpp") + +target_compile_features(standalone_miri PUBLIC cxx_std_14) + +find_package(Threads REQUIRED) + +target_link_libraries(standalone_miri + PUBLIC + Threads::Threads + common) + +target_include_directories(standalone_miri + PUBLIC + . + ../../src/include) diff --git a/tools/testrunner/CMakeLists.txt b/tools/testrunner/CMakeLists.txt new file mode 100644 index 000000000..c9534c88f --- /dev/null +++ b/tools/testrunner/CMakeLists.txt @@ -0,0 +1,17 @@ +# Build outline for Standalone MIRI: +# +# Sourcefiles: All inside testrunner directory +# Dependencies: libCommon +# Notes: Needs compiler capable of C++14. Disables Warnings. + + +############################################################################### +# Compile TestRunner # +############################################################################### +add_executable(test_runner "main.cpp") + +target_compile_features(test_runner PUBLIC cxx_std_14) + +target_link_libraries(test_runner + PUBLIC + common) From fb4c7fa696a1d3994655c3686750c01d3a94784c Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Sun, 21 Oct 2018 14:51:24 +0200 Subject: [PATCH 02/15] Update README.md Add early buildsteps for cmake --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index bbc34fb62..7c8429213 100644 --- a/README.md +++ b/README.md @@ -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 ======================= From 4d9384265e08053353995523ba817ad2f5a27d35 Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Sun, 21 Oct 2018 15:03:06 +0200 Subject: [PATCH 03/15] CMake: Remove comments about old makefile --- CMakeLists.txt | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b94db695e..7df0c0f83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,14 +85,6 @@ add_subdirectory(tools/testrunner) # Compile mrustc # ############################################################################### -# Set up some meta-information -# $V$(CXX) -o $@ -c $< $(CXXFLAGS) $(CPPFLAGS) -MMD -MP -MF $@.dep -# -D VERSION_GIT_FULLHASH=\"$(shell git show --pretty=%H -s)\" -# -D VERSION_GIT_BRANCH="\"$(shell git symbolic-ref -q --short HEAD || git describe --tags --exact-match)\"" -# -D VERSION_GIT_SHORTHASH=\"$(shell git show -s --pretty=%h)\" -# -D VERSION_BUILDTIME="\"$(shell date -uR)\"" -# -D VERSION_GIT_ISDIRTY=$(shell git diff-index --quiet HEAD; echo $$?) - #! gather_git_info : Populates variables with the current commit hash, branch, ... # # Defines the following variables: @@ -119,7 +111,7 @@ function(gather_git_info) endfunction() gather_git_info() -string(TIMESTAMP BUILD_TIMESTAMP ) +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}") From 9c8e7bb4193d46ad3ba193d4dc1d1b31a87b3d92 Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Sun, 21 Oct 2018 15:09:33 +0200 Subject: [PATCH 04/15] CMake: Refactor downloading rustc-sources --- CMakeLists.txt | 74 ++++----------------------------- cmake/DownloadRustcSource.cmake | 40 ++++++++++++++++++ cmake/GatherGitInfo.cmake | 26 ++++++++++++ 3 files changed, 74 insertions(+), 66 deletions(-) create mode 100644 cmake/DownloadRustcSource.cmake create mode 100644 cmake/GatherGitInfo.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7df0c0f83..376e8ff6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,8 @@ cmake_minimum_required(VERSION 3.4) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(ExternalProject) -include(GetGitRevisionDescription) +include(GatherGitInfo) +include(DownloadRustcSource) # - [x] Find exact rustc version to be downloaded # - [x] Download rustc-source @@ -31,48 +32,13 @@ set(MRUSTC_RUSTC_SOURCE_HASH # Download rustc-source # ############################################################################# - -#! download_rustc_source : Downloads the rustc-source from the location specified inside -# MRUSTC_RUSTC_SOURCE_URL -# -# Defines ${TARGET}_DIRECTORY. -# -# \param:TARGET Set the name of the target which will trigger the download. -# \group:DEPENDS List of targets the download should depend upon -# -function(download_rustc_source) - set(options "") - set(oneValueArgs TARGET ) - set(multiValueArgs DEPENDS) - cmake_parse_arguments(DL_RUSTC - "${options}" - "${oneValueArgs}" - "${multiValueArgs}" - ${ARGN}) - - if (NOT MRUSTC_RUSTC_SOURCE_URL) - message(FATAL_ERROR "MRUSTC_RUSTC_SOURCE_URL is not set! Please specify where the rustc-sources are!") - endif() - - if (NOT DL_RUSTC_TARGET) - message(FATAL_ERROR "TARGET property of download_rustc_source must be set!") - endif() - - set(${DL_RUSTC_TARGET}_DIRECTORY ${CMAKE_BINARY_DIR}/rustc-source PARENT_SCOPE) - - ExternalProject_Add(${DL_RUSTC_TARGET} - PREFIX ${${DL_RUSTC_TARGET}_DIRECTORY} - URL ${MRUSTC_RUSTC_SOURCE_URL} - URL_HASH ${MRUSTC_RUSTC_SOURCE_HASH} - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - DEPENDS ${DL_RUSTC_DEPENDS}) -endfunction() - -download_rustc_source(TARGET rustc_source) +download_rustc_source( + TARGET get_rustc_source + URL ${MRUSTC_RUSTC_SOURCE_URL} + HASH ${MRUSTC_RUSTC_SOURCE_HASH}) # add_dependencies(hello_world rustc_source) + ############################################################################### # Compile Tools (Minicargo, ...) # ############################################################################### @@ -81,35 +47,11 @@ add_subdirectory(tools/minicargo) add_subdirectory(tools/standalone_miri) add_subdirectory(tools/testrunner) + ############################################################################### # Compile mrustc # ############################################################################### -#! 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) - 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) - - 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() - gather_git_info() string(TIMESTAMP BUILD_TIMESTAMP UTC) message(STATUS "Git status: ${GIT_IS_DIRTY}") diff --git a/cmake/DownloadRustcSource.cmake b/cmake/DownloadRustcSource.cmake new file mode 100644 index 000000000..fd6fbdddd --- /dev/null +++ b/cmake/DownloadRustcSource.cmake @@ -0,0 +1,40 @@ + +#! download_rustc_source : Downloads the rustc-source from the location specified inside +# MRUSTC_RUSTC_SOURCE_URL +# +# Defines ${TARGET}_DIRECTORY. +# +# \param:TARGET Set the name of the target which will trigger the download. +# \param:URL URL or Path to download the sources from +# \param:HASH (optional) Hash of the downloaded archive (ie. SHA256=...) +# \group:DEPENDS List of targets the download should depend upon +# +function(download_rustc_source) + set(options "") + set(oneValueArgs TARGET URL HASH) + set(multiValueArgs DEPENDS) + cmake_parse_arguments(DL_RUSTC + "${options}" + "${oneValueArgs}" + "${multiValueArgs}" + ${ARGN}) + + if (NOT MRUSTC_RUSTC_SOURCE_URL) + message(FATAL_ERROR "MRUSTC_RUSTC_SOURCE_URL is not set! Please specify where the rustc-sources are!") + endif() + + if (NOT DL_RUSTC_TARGET) + message(FATAL_ERROR "TARGET property of download_rustc_source must be set!") + endif() + + set(${DL_RUSTC_TARGET}_DIRECTORY ${CMAKE_BINARY_DIR}/rustc-source PARENT_SCOPE) + + ExternalProject_Add(${DL_RUSTC_TARGET} + PREFIX ${${DL_RUSTC_TARGET}_DIRECTORY} + URL ${DL_RUSTC_URL} + URL_HASH ${DL_RUSTC_HASH} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + DEPENDS ${DL_RUSTC_DEPENDS}) +endfunction() diff --git a/cmake/GatherGitInfo.cmake b/cmake/GatherGitInfo.cmake new file mode 100644 index 000000000..5cc59a1c9 --- /dev/null +++ b/cmake/GatherGitInfo.cmake @@ -0,0 +1,26 @@ +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) + 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) + + 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() From 2b0b8064243c50c374b8fd9af26f97ba7156f1aa Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Sun, 21 Oct 2018 15:18:37 +0200 Subject: [PATCH 05/15] CMake: Put all sourcefiles of mrustc into src/CMakeLists.txt --- src/CMakeLists.txt | 223 ++++++++++++++++++++++++++++----- src/ast/CMakeLists.txt | 21 ---- src/expand/CMakeLists.txt | 23 ---- src/hir/CMakeLists.txt | 43 ------- src/hir_conv/CMakeLists.txt | 9 -- src/hir_expand/CMakeLists.txt | 10 -- src/hir_typeck/CMakeLists.txt | 18 --- src/include/CMakeLists.txt | 2 - src/macro_rules/CMakeLists.txt | 9 -- src/mir/CMakeLists.txt | 22 ---- src/parse/CMakeLists.txt | 24 ---- src/resolve/CMakeLists.txt | 7 -- src/trans/CMakeLists.txt | 22 ---- 13 files changed, 192 insertions(+), 241 deletions(-) delete mode 100644 src/ast/CMakeLists.txt delete mode 100644 src/expand/CMakeLists.txt delete mode 100644 src/hir/CMakeLists.txt delete mode 100644 src/hir_conv/CMakeLists.txt delete mode 100644 src/hir_expand/CMakeLists.txt delete mode 100644 src/hir_typeck/CMakeLists.txt delete mode 100644 src/include/CMakeLists.txt delete mode 100644 src/macro_rules/CMakeLists.txt delete mode 100644 src/mir/CMakeLists.txt delete mode 100644 src/parse/CMakeLists.txt delete mode 100644 src/resolve/CMakeLists.txt delete mode 100644 src/trans/CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1a5ff8b49..a6f609efe 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,47 +1,208 @@ # Build outline for mrustc: # -# Sourcefiles: -# Dependencies: +# Sourcefiles: +# Dependencies: # Notes: Needs compiler capable of C++14 -add_subdirectory(include) -add_subdirectory(ast) -add_subdirectory(expand) -add_subdirectory(hir) -add_subdirectory(hir_conv) -add_subdirectory(hir_expand) -add_subdirectory(hir_typeck) -add_subdirectory(macro_rules) -add_subdirectory(mir) -add_subdirectory(parse) -add_subdirectory(resolve) -add_subdirectory(trans) +find_package(ZLIB REQUIRED) add_executable(mrustc - main.cpp + include/synext_macro.hpp + include/main_bindings.hpp + include/compile_error.hpp + include/rc_string.hpp + include/string_view.hpp + include/version.hpp + include/stdspan.hpp + include/ident.hpp + include/debug.hpp + include/synext_decorator.hpp + include/cpp_unpack.h + include/synext.hpp + include/tagged_union.hpp + include/span.hpp + hir/visitor.hpp + hir/expr_ptr.hpp + hir/generic_params.hpp + hir/generic_params.cpp + hir/type.cpp + hir/path.hpp + hir/main_bindings.hpp + hir/crate_post_load.cpp + hir/from_ast.hpp + hir/dump.cpp + hir/hir.cpp + hir/type.hpp + hir/hir.hpp + hir/pattern.cpp + hir/expr_ptr.cpp + hir/crate_ptr.cpp + hir/from_ast.cpp + hir/serialise.cpp + hir/expr.cpp + hir/pattern.hpp + hir/visitor.cpp + hir/serialise_lowlevel.hpp + hir/crate_ptr.hpp + hir/expr_state.hpp + hir/serialise_lowlevel.cpp + hir/path.cpp + hir/deserialise.cpp + hir/item_path.hpp + hir/from_ast_expr.cpp + hir/expr.hpp + parse/root.cpp + parse/lex.hpp + parse/common.hpp + parse/types.cpp + parse/tokentree.cpp + parse/token.hpp + parse/pattern.cpp + parse/paths.cpp + parse/interpolated_fragment.hpp + parse/ttstream.cpp + parse/token.cpp + parse/ttstream.hpp + parse/expr.cpp + parse/lex.cpp + parse/interpolated_fragment.cpp + parse/parseerror.hpp + parse/parseerror.cpp + parse/eTokenType.enum.h + parse/tokentree.hpp + parse/tokenstream.hpp + parse/tokenstream.cpp + hir_conv/main_bindings.hpp + hir_conv/bind.cpp + hir_conv/expand_type.cpp + hir_conv/resolve_ufcs.cpp + hir_conv/markings.cpp + hir_conv/constant_evaluation.cpp + resolve/main_bindings.hpp + resolve/absolute.cpp + resolve/use.cpp + resolve/index.cpp + expand/crate_tags.cpp + expand/cfg.hpp + expand/concat.cpp + expand/format_args.cpp + expand/derive.cpp + expand/std_prelude.cpp + expand/env.cpp + expand/cfg.cpp + expand/macro_rules.cpp + expand/test_harness.cpp + expand/include.cpp + expand/mod.cpp + expand/asm.cpp + expand/file_line.cpp + expand/lang_item.cpp + expand/test.cpp + expand/proc_macro.cpp + expand/stringify.cpp + expand/proc_macro.hpp + expand/rustc_diagnostics.cpp + hir_typeck/helpers.hpp + hir_typeck/helpers.cpp + hir_typeck/expr_visit.cpp + hir_typeck/expr_visit.hpp + hir_typeck/expr_check.cpp + hir_typeck/impl_ref.hpp + hir_typeck/main_bindings.hpp + hir_typeck/expr_cs.cpp + hir_typeck/common.hpp + hir_typeck/impl_ref.cpp + hir_typeck/static.cpp + hir_typeck/static.hpp + hir_typeck/outer.cpp + hir_typeck/common.cpp + span.cpp + coretypes.hpp + macro_rules/parse.cpp + macro_rules/macro_rules_ptr.hpp + macro_rules/pattern_checks.hpp + macro_rules/mod.cpp + macro_rules/eval.cpp + macro_rules/macro_rules.hpp + hir_expand/erased_types.cpp + hir_expand/main_bindings.hpp + hir_expand/closures.cpp + hir_expand/annotate_value_usage.cpp + hir_expand/vtable.cpp + hir_expand/ufcs_everything.cpp + hir_expand/reborrow.cpp + trans/enumerate.cpp + trans/codegen.cpp + trans/monomorphise.hpp + trans/mangling.cpp + trans/target.hpp + trans/target.cpp + trans/trans_list.cpp + trans/main_bindings.hpp + trans/codegen_mmir.cpp + trans/monomorphise.cpp + trans/allocator.cpp + trans/codegen_c.cpp + trans/codegen_c_structured.cpp + trans/trans_list.hpp + trans/mangling.hpp + trans/codegen_c.hpp + trans/allocator.hpp + trans/codegen.hpp + rc_string.cpp + mir/check_full.cpp + mir/from_hir.hpp + mir/operations.hpp + mir/helpers.hpp + mir/helpers.cpp + mir/optimise.cpp + mir/mir.hpp + mir/main_bindings.hpp + mir/mir.cpp + mir/dump.cpp + mir/visit_crate_mir.cpp + mir/mir_ptr.hpp + mir/mir_builder.cpp + mir/from_hir_match.cpp + mir/cleanup.cpp + mir/check.cpp + mir/from_hir.cpp + mir/visit_crate_mir.hpp + mir/mir_ptr.cpp + ast/expr_ptr.hpp + ast/types.hpp + ast/path.hpp + ast/attrs.hpp + ast/types.cpp + ast/item.hpp + ast/crate.hpp + ast/dump.cpp + ast/macro.hpp + ast/crate.cpp + ast/ast.hpp + ast/pattern.cpp + ast/expr.cpp + ast/pattern.hpp + ast/path.cpp + ast/ast.cpp + ast/generics.hpp + ast/expr.hpp + version.cpp debug.cpp + main.cpp ident.cpp - rc_string.cpp - span.cpp - version.cpp) + common.hpp) target_link_libraries(mrustc PRIVATE common # tools-directory - ast - expand - hir - hir_conv - hir_expand - hir_typeck - macro_rules - mir - parse - resolve - trans - INTERFACE - include) + ZLIB::ZLIB) + +target_include_directories(mrustc + PRIVATE + include + .) target_compile_definitions(mrustc PRIVATE -DVERSION_GIT_FULLHASH="${GIT_HEAD_HASH}" diff --git a/src/ast/CMakeLists.txt b/src/ast/CMakeLists.txt deleted file mode 100644 index 005e78cd7..000000000 --- a/src/ast/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -add_library(ast STATIC - "ast.cpp" - "ast.hpp" - "attrs.hpp" - "crate.cpp" - "crate.hpp" - "dump.cpp" - "expr.cpp" - "expr.hpp" - "expr_ptr.hpp" - "generics.hpp" - "item.hpp" - "macro.hpp" - "path.cpp" - "path.hpp" - "pattern.cpp" - "pattern.hpp" - "types.cpp" - "types.hpp") - -target_link_libraries(ast PUBLIC shared_includes) diff --git a/src/expand/CMakeLists.txt b/src/expand/CMakeLists.txt deleted file mode 100644 index 8946c5882..000000000 --- a/src/expand/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -add_library(expand STATIC - asm.cpp - cfg.cpp - cfg.hpp - concat.cpp - crate_tags.cpp - derive.cpp - env.cpp - file_line.cpp - format_args.cpp - include.cpp - lang_item.cpp - macro_rules.cpp - mod.cpp - proc_macro.cpp - proc_macro.hpp - rustc_diagnostics.cpp - std_prelude.cpp - stringify.cpp - test.cpp - test_harness.cpp) - -target_link_libraries(expand PUBLIC shared_includes) diff --git a/src/hir/CMakeLists.txt b/src/hir/CMakeLists.txt deleted file mode 100644 index c4a71ab65..000000000 --- a/src/hir/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ - -find_package(ZLIB REQUIRED) - - -add_library(hir STATIC - crate_post_load.cpp - crate_ptr.cpp - crate_ptr.hpp - deserialise.cpp - dump.cpp - expr.cpp - expr.hpp - expr_ptr.cpp - expr_ptr.hpp - expr_state.hpp - from_ast.cpp - from_ast_expr.cpp - from_ast.hpp - generic_params.cpp - generic_params.hpp - hir.cpp - hir.hpp - item_path.hpp - main_bindings.hpp - path.cpp - path.hpp - pattern.cpp - pattern.hpp - serialise.cpp - serialise_lowlevel.cpp - serialise_lowlevel.hpp - type.cpp - type.hpp - visitor.cpp - visitor.hpp - ) - -target_link_libraries(hir - PUBLIC - shared_includes - PRIVATE - ZLIB::ZLIB) - diff --git a/src/hir_conv/CMakeLists.txt b/src/hir_conv/CMakeLists.txt deleted file mode 100644 index 473bed467..000000000 --- a/src/hir_conv/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -add_library(hir_conv STATIC - bind.cpp - constant_evaluation.cpp - expand_type.cpp - main_bindings.hpp - markings.cpp - resolve_ufcs.cpp) - -target_link_libraries(hir_conv PUBLIC shared_includes) diff --git a/src/hir_expand/CMakeLists.txt b/src/hir_expand/CMakeLists.txt deleted file mode 100644 index 726c6507a..000000000 --- a/src/hir_expand/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -add_library(hir_expand STATIC - annotate_value_usage.cpp - closures.cpp - erased_types.cpp - main_bindings.hpp - reborrow.cpp - ufcs_everything.cpp - vtable.cpp) - -target_link_libraries(hir_expand PUBLIC shared_includes) diff --git a/src/hir_typeck/CMakeLists.txt b/src/hir_typeck/CMakeLists.txt deleted file mode 100644 index d8df329ee..000000000 --- a/src/hir_typeck/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -add_library(hir_typeck STATIC - CMakeLists.txt - common.cpp - common.hpp - expr_check.cpp - expr_cs.cpp - expr_visit.cpp - expr_visit.hpp - helpers.cpp - helpers.hpp - impl_ref.cpp - impl_ref.hpp - main_bindings.hpp - outer.cpp - static.cpp - static.hpp) - -target_link_libraries(hir_typeck PUBLIC shared_includes) diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt deleted file mode 100644 index 5d1e7b7ab..000000000 --- a/src/include/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_library(shared_includes INTERFACE) -target_include_directories(shared_includes INTERFACE . ..) diff --git a/src/macro_rules/CMakeLists.txt b/src/macro_rules/CMakeLists.txt deleted file mode 100644 index 7600da334..000000000 --- a/src/macro_rules/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -add_library(macro_rules STATIC - eval.cpp - macro_rules.hpp - macro_rules_ptr.hpp - mod.cpp - parse.cpp - pattern_checks.hpp) - -target_link_libraries(macro_rules PUBLIC shared_includes) diff --git a/src/mir/CMakeLists.txt b/src/mir/CMakeLists.txt deleted file mode 100644 index 3de7ec31f..000000000 --- a/src/mir/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -add_library(mir STATIC - check.cpp - check_full.cpp - cleanup.cpp - dump.cpp - from_hir.cpp - from_hir.hpp - from_hir_match.cpp - helpers.cpp - helpers.hpp - main_bindings.hpp - mir_builder.cpp - mir.cpp - mir.hpp - mir_ptr.cpp - mir_ptr.hpp - operations.hpp - optimise.cpp - visit_crate_mir.cpp - visit_crate_mir.hpp) - -target_link_libraries(mir PUBLIC shared_includes) diff --git a/src/parse/CMakeLists.txt b/src/parse/CMakeLists.txt deleted file mode 100644 index c8262af6e..000000000 --- a/src/parse/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -add_library(parse STATIC - common.hpp - eTokenType.enum.h - expr.cpp - interpolated_fragment.cpp - interpolated_fragment.hpp - lex.cpp - lex.hpp - parseerror.cpp - parseerror.hpp - paths.cpp - pattern.cpp - root.cpp - token.cpp - token.hpp - tokenstream.cpp - tokenstream.hpp - tokentree.cpp - tokentree.hpp - ttstream.cpp - ttstream.hpp - types.cpp) - -target_link_libraries(parse PUBLIC shared_includes) diff --git a/src/resolve/CMakeLists.txt b/src/resolve/CMakeLists.txt deleted file mode 100644 index c144d6eef..000000000 --- a/src/resolve/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_library(resolve STATIC - absolute.cpp - index.cpp - main_bindings.hpp - use.cpp) - -target_link_libraries(resolve PUBLIC shared_includes) diff --git a/src/trans/CMakeLists.txt b/src/trans/CMakeLists.txt deleted file mode 100644 index 9d3bb06c0..000000000 --- a/src/trans/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -add_library(trans STATIC - allocator.cpp - allocator.hpp - codegen_c.cpp - codegen_c.hpp - codegen.cpp - codegen_c_structured.cpp - codegen.hpp - codegen_mmir.cpp - enumerate.cpp - main_bindings.hpp - mangling.cpp - mangling.hpp - monomorphise.cpp - monomorphise.hpp - target.cpp - target.hpp - trans_list.cpp - trans_list.hpp) - -target_link_libraries(trans PUBLIC shared_includes) -target_link_libraries(trans PRIVATE common) From b58673e69c52b13d43b6818fe4da895e5d05deed Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Sun, 21 Oct 2018 15:24:31 +0200 Subject: [PATCH 06/15] .gitignore: Add CMake standarf "build" directory --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index e60401677..a73797401 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,6 @@ /bnf/rust.tab.h /bnf/rust.output /bnf/test.bin + +# CMake build folder +build/ \ No newline at end of file From 8f65ce8c54b5b5837269b33b204af3d727d72853 Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Fri, 23 Nov 2018 20:32:43 +0100 Subject: [PATCH 07/15] CMake: Don't pass files as strings everywhere --- tools/common/CMakeLists.txt | 16 +++++++------- tools/minicargo/CMakeLists.txt | 16 +++++++------- tools/standalone_miri/CMakeLists.txt | 32 ++++++++++++++-------------- tools/testrunner/CMakeLists.txt | 2 +- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/tools/common/CMakeLists.txt b/tools/common/CMakeLists.txt index 8cb8c257b..5ec3d4ea2 100644 --- a/tools/common/CMakeLists.txt +++ b/tools/common/CMakeLists.txt @@ -10,14 +10,14 @@ # Compile libCommon # ############################################################################### add_library(common STATIC - "debug.h" - "debug.cpp" - "helpers.h" - "path.h" - "path.cpp" - "target_detect.h" - "toml.h" - "toml.cpp") + debug.h + debug.cpp + helpers.h + path.h + path.cpp + target_detect.h + toml.h + toml.cpp) target_compile_features(common PUBLIC cxx_std_14) target_include_directories(common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/tools/minicargo/CMakeLists.txt b/tools/minicargo/CMakeLists.txt index 5e194bdc4..753dddaff 100644 --- a/tools/minicargo/CMakeLists.txt +++ b/tools/minicargo/CMakeLists.txt @@ -10,14 +10,14 @@ # Compile Minicargo # ############################################################################### add_executable(minicargo - "build.h" - "build.cpp" - "main.cpp" - "manifest.h" - "manifest.cpp" - "repository.h" - "repository.cpp" - "stringlist.h") + build.h + build.cpp + main.cpp + manifest.h + manifest.cpp + repository.h + repository.cpp + stringlist.h) target_compile_features(minicargo PUBLIC cxx_std_14) diff --git a/tools/standalone_miri/CMakeLists.txt b/tools/standalone_miri/CMakeLists.txt index 6e73758ef..4ca031c9c 100644 --- a/tools/standalone_miri/CMakeLists.txt +++ b/tools/standalone_miri/CMakeLists.txt @@ -10,22 +10,22 @@ # Compile Standalone MIRI # ############################################################################### add_executable(standalone_miri - "hir/type.hpp" - "CMakeLists.txt" - "debug.cpp" - "debug.hpp" - "hir_sim.cpp" - "hir_sim.hpp" - "lex.cpp" - "lex.hpp" - "main.cpp" - "mir.cpp" - "miri.cpp" - "miri.hpp" - "module_tree.cpp" - "module_tree.hpp" - "value.cpp" - "value.hpp") + hir/type.hpp + CMakeLists.txt + debug.cpp + debug.hpp + hir_sim.cpp + hir_sim.hpp + lex.cpp + lex.hpp + main.cpp + mir.cpp + miri.cpp + miri.hpp + module_tree.cpp + module_tree.hpp + value.cpp + value.hpp) target_compile_features(standalone_miri PUBLIC cxx_std_14) diff --git a/tools/testrunner/CMakeLists.txt b/tools/testrunner/CMakeLists.txt index c9534c88f..0af30368b 100644 --- a/tools/testrunner/CMakeLists.txt +++ b/tools/testrunner/CMakeLists.txt @@ -8,7 +8,7 @@ ############################################################################### # Compile TestRunner # ############################################################################### -add_executable(test_runner "main.cpp") +add_executable(test_runner main.cpp) target_compile_features(test_runner PUBLIC cxx_std_14) From c7b54c79410cb189492c5e19a4c3b17d36b55378 Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Tue, 27 Nov 2018 11:18:52 +0100 Subject: [PATCH 08/15] Minicargo: Use correct mrustc-path for cmake --- tools/minicargo/build.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp index 35c64f3b6..f3884042b 100644 --- a/tools/minicargo/build.cpp +++ b/tools/minicargo/build.cpp @@ -545,7 +545,7 @@ Builder::Builder(BuildOptions opts): ::helpers::path minicargo_path { buf }; minicargo_path.pop_component(); # ifdef __MINGW32__ - m_compiler_path = (minicargo_path / "..\\..\\bin\\mrustc.exe").normalise(); + m_compiler_path = (minicargo_path / "mrustc.exe").normalise(); # else // MSVC, minicargo and mrustc are in the same dir m_compiler_path = minicargo_path / "mrustc.exe"; @@ -584,7 +584,7 @@ Builder::Builder(BuildOptions opts): ::helpers::path minicargo_path { buf }; minicargo_path.pop_component(); - m_compiler_path = (minicargo_path / "../../bin/mrustc").normalise(); + m_compiler_path = (minicargo_path / "mrustc").normalise(); #endif } From b189a4beea7be754a4745daea48d4f50d3fda965 Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Tue, 27 Nov 2018 11:19:45 +0100 Subject: [PATCH 09/15] mrustc: Add mrustc_version library so a change in timestamp doesn't rebuild everything --- src/CMakeLists.txt | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a6f609efe..749ffe396 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,18 @@ find_package(ZLIB REQUIRED) +# Add library for version.cpp so we don't have to recompile +# everything when the timestamp changes. +add_library(mrustc_version STATIC version.cpp) + +target_include_directories(mrustc_version PRIVATE include .) +target_compile_definitions(mrustc_version PRIVATE + -DVERSION_GIT_FULLHASH="${GIT_HEAD_HASH}" + -DVERSION_GIT_SHORTHASH="${GIT_HEAD_HASH_SHORT}" + -DVERSION_GIT_BRANCH="${GIT_BRANCH}" + -DVERSION_GIT_ISDIRTY=$ + -DVERSION_BUILDTIME="${BUILD_TIMESTAMP}") + add_executable(mrustc include/synext_macro.hpp include/main_bindings.hpp @@ -188,7 +200,6 @@ add_executable(mrustc ast/ast.cpp ast/generics.hpp ast/expr.hpp - version.cpp debug.cpp main.cpp ident.cpp @@ -196,6 +207,7 @@ add_executable(mrustc target_link_libraries(mrustc PRIVATE + mrustc_version common # tools-directory ZLIB::ZLIB) @@ -203,10 +215,3 @@ target_include_directories(mrustc PRIVATE include .) - -target_compile_definitions(mrustc PRIVATE - -DVERSION_GIT_FULLHASH="${GIT_HEAD_HASH}" - -DVERSION_GIT_SHORTHASH="${GIT_HEAD_HASH_SHORT}" - -DVERSION_GIT_BRANCH="${GIT_BRANCH}" - -DVERSION_GIT_ISDIRTY=$ - -DVERSION_BUILDTIME="${BUILD_TIMESTAMP}") From 1fdd5b971b85b06aad647a80fc224d7969d44d54 Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Tue, 27 Nov 2018 11:26:16 +0100 Subject: [PATCH 10/15] CMake: Simplify downloading rustc-sources --- CMakeLists.txt | 39 +++++++++++++++++++++++--------- cmake/DownloadRustcSource.cmake | 40 --------------------------------- 2 files changed, 29 insertions(+), 50 deletions(-) delete mode 100644 cmake/DownloadRustcSource.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 376e8ff6e..2bc34e332 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,6 @@ cmake_minimum_required(VERSION 3.4) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(ExternalProject) include(GatherGitInfo) -include(DownloadRustcSource) # - [x] Find exact rustc version to be downloaded # - [x] Download rustc-source @@ -16,28 +15,48 @@ include(DownloadRustcSource) # 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://github.com/rust-lang/rust/archive/1.19.0.tar.gz" + "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. ") + "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=7e1ecb476118b79b5abed02bc7a724bb65413057e26f1d2b8538c572f7463be0" + "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 # ############################################################################# -download_rustc_source( - TARGET get_rustc_source - URL ${MRUSTC_RUSTC_SOURCE_URL} - HASH ${MRUSTC_RUSTC_SOURCE_HASH}) -# add_dependencies(hello_world 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, ...) # diff --git a/cmake/DownloadRustcSource.cmake b/cmake/DownloadRustcSource.cmake deleted file mode 100644 index fd6fbdddd..000000000 --- a/cmake/DownloadRustcSource.cmake +++ /dev/null @@ -1,40 +0,0 @@ - -#! download_rustc_source : Downloads the rustc-source from the location specified inside -# MRUSTC_RUSTC_SOURCE_URL -# -# Defines ${TARGET}_DIRECTORY. -# -# \param:TARGET Set the name of the target which will trigger the download. -# \param:URL URL or Path to download the sources from -# \param:HASH (optional) Hash of the downloaded archive (ie. SHA256=...) -# \group:DEPENDS List of targets the download should depend upon -# -function(download_rustc_source) - set(options "") - set(oneValueArgs TARGET URL HASH) - set(multiValueArgs DEPENDS) - cmake_parse_arguments(DL_RUSTC - "${options}" - "${oneValueArgs}" - "${multiValueArgs}" - ${ARGN}) - - if (NOT MRUSTC_RUSTC_SOURCE_URL) - message(FATAL_ERROR "MRUSTC_RUSTC_SOURCE_URL is not set! Please specify where the rustc-sources are!") - endif() - - if (NOT DL_RUSTC_TARGET) - message(FATAL_ERROR "TARGET property of download_rustc_source must be set!") - endif() - - set(${DL_RUSTC_TARGET}_DIRECTORY ${CMAKE_BINARY_DIR}/rustc-source PARENT_SCOPE) - - ExternalProject_Add(${DL_RUSTC_TARGET} - PREFIX ${${DL_RUSTC_TARGET}_DIRECTORY} - URL ${DL_RUSTC_URL} - URL_HASH ${DL_RUSTC_HASH} - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - DEPENDS ${DL_RUSTC_DEPENDS}) -endfunction() From 09a4660089b0f2aea11eab42bad6bb2c2bed4139 Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Tue, 27 Nov 2018 11:29:00 +0100 Subject: [PATCH 11/15] CMake: Build some rust standard libraries --- CMakeLists.txt | 39 +++++++++++++++++++++++++- tools/minicargo/CMakeLists.txt | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bc34e332..01e95a3c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,5 +80,42 @@ 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) diff --git a/tools/minicargo/CMakeLists.txt b/tools/minicargo/CMakeLists.txt index 753dddaff..d9f2869ae 100644 --- a/tools/minicargo/CMakeLists.txt +++ b/tools/minicargo/CMakeLists.txt @@ -24,3 +24,53 @@ target_compile_features(minicargo PUBLIC cxx_std_14) find_package(Threads REQUIRED) target_link_libraries(minicargo Threads::Threads) target_link_libraries(minicargo common) + + +#! build_rust_std_lib : Builds a rust standard library +# +# \param:TARGET Set the name of the target which will trigger the build. +# \param:CRATE_TO_BUILD Path to the crate to build +# \group:DEPENDS List of targets the download should depend upon +# +function(build_rust_std_lib) + set(options "") + set(oneValueArgs + TARGET + CRATE_TO_BUILD) + + set(multiValueArgs + DEPENDS) + + cmake_parse_arguments( + BRL # Build Rustc Lib + "${options}" + "${oneValueArgs}" + "${multiValueArgs}" + ${ARGN}) + + message(STATUS "Building minicargo-target ${BRL_TARGET} at ${BRL_CRATE_TO_BUILD}") + message(STATUS "Executable output path: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") + + if(UNIX AND NOT APPLE) + # for Linux, BSD, Solaris, Minix. FIXME: More cases to support these platforms + set(OVERRIDE_SUFFIX "-linux") + elseif(APPLE) + set(OVERRIDE_SUFFIX "-macos") + elseif(MSVC) + set(OVERRIDE_SUFFIX "") # Nothing for Win32? + else() + set(OVERRIDE_SUFFIX "") + endif() + + set(OVERRIDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/script-overrides/${MRUSTC_RUSTC_CHANNEL}-${MRUSTC_RUSTC_VERSION}${OVERRIDE_SUFFIX}") + + # Path to minicargo executable + set(MINICARGO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/minicargo) + + add_custom_target(${BRL_TARGET} + COMMAND ${MINICARGO} ${BRL_CRATE_TO_BUILD} + --script-overrides ${OVERRIDE_DIR} + --output-dir output + DEPENDS minicargo mrustc ${BRL_DEPENDS} + ) +endfunction() From 1713115114f0f3f6a8db0adfad8449da7fb1849e Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Mon, 3 Dec 2018 11:39:17 +0100 Subject: [PATCH 12/15] CMake: Add defaults for when git info extraction fails --- cmake/GatherGitInfo.cmake | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cmake/GatherGitInfo.cmake b/cmake/GatherGitInfo.cmake index 5cc59a1c9..4695b0a58 100644 --- a/cmake/GatherGitInfo.cmake +++ b/cmake/GatherGitInfo.cmake @@ -13,10 +13,18 @@ include(GetGitRevisionDescription) 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) - 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) + + 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) From 327a1f218f268eb0639be0da90ab0520eacf80a9 Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Mon, 3 Dec 2018 10:52:18 +0100 Subject: [PATCH 13/15] CMake: Make Travis work --- .travis.yml | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 864d973da..3f24008ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,24 +17,34 @@ 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 +# 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 From fecc7ff3afa990fd6e36ca0535ad3b84268d1986 Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Tue, 18 Dec 2018 20:40:22 +0100 Subject: [PATCH 14/15] Travis: Build rust std libraries --- .travis.yml | 2 ++ CMakeLists.txt | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3f24008ed..cd9864c95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,6 +39,8 @@ script: - 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 01e95a3c9..4d13e0ae2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,7 +115,8 @@ build_rust_std_lib( add_custom_target(rust_standard_libs ALL DEPENDS rust_libstd - # rust_libpanic_unwind + rust_libpanic_unwind rust_libtest rust_libgetopts - rust_libproc_macro) + # rust_libproc_macro + ) From 3bdf071fe8fc47dd383a9fe8c315af28dc953313 Mon Sep 17 00:00:00 2001 From: Andre Taulien Date: Tue, 18 Dec 2018 20:57:19 +0100 Subject: [PATCH 15/15] Travis: Don't compile rust std-libraries --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cd9864c95..22749decc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ script: - cmake .. - make mrustc -j4 - make minicargo -j4 - - make rust_standard_libs -j4 + # - make rust_standard_libs -j4 # Test # - make -f minicargo.mk output/libtest.hir # libstd