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 with meson #89

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@
/bnf/rust.tab.h
/bnf/rust.output
/bnf/test.bin

/subprojects/*
!/subprojects/*.wrap
/build*
50 changes: 50 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
project(
'mrustc',
'cpp',
version: '0.8.0',
license: 'MIT',
default_options: [
'cpp_std=c++14',
'werror=false',
'warning_level=2',
],
)

python = import('python').find_installation('python3')
major_version = 0
minor_version = 8
patch_version = 0

compiler = meson.get_compiler('cpp').get_id()
if compiler == 'msvc'
add_project_arguments(
'-wd4267',
'-wd4244',
'-wd4099',
'-wd4996',
'-wd4146',
language: 'cpp',
)
endif

subdir('tools/common')
subdir('tools/minicargo')
subdir('tools/standalone_miri')
subdir('tools/testrunner')

subdir('src')

rustc_source_url = get_option('rustc_source_url')
rustc_source_hash = get_option('rustc_source_hash')
'''rustc_source = custom_target(
'rustc_source',
input: 'download_rustc_source.py',
build_always_stale: true,
install: false,
command: [
python, '@INPUT@',
'--output-directory', 'rustc_source',
'--source-url', rustc_source_url,
'--source-hash', rustc_source_hash,
],
)'''
14 changes: 14 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
option(
'rustc_source_url',
type: 'string',
value: 'https://github.com/rust-lang/rust/archive/1.19.0.tar.gz',
description: 'URL or local path of where rustc\'s source should be downloaded from.',
)

option(
'rustc_source_hash',
type: 'string',
value: 'SHA256=7e1ecb476118b79b5abed02bc7a724bb65413057e26f1d2b8538c572f7463be0',
description:
'SHA256 of the file downloaded from MRUSTC_RUSTC_SOURCE_URL. You can leave this empty to skip verifying whether the downloaded archive is correct.',
)
84 changes: 40 additions & 44 deletions src/ast/attrs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,7 @@

namespace AST {

//
class Attribute;
::std::ostream& operator<<(::std::ostream& os, const Attribute& x);

/// A list of attributes on an item (searchable by the attribute name)
class AttributeList
{
public:
::std::vector<Attribute> m_items;

AttributeList() {}
AttributeList(::std::vector<Attribute> items):
m_items( mv$(items) )
{
}

// Move present
AttributeList(AttributeList&&) = default;
AttributeList& operator=(AttributeList&&) = default;
// No copy assign, but explicit copy
explicit AttributeList(const AttributeList&) = default;
AttributeList& operator=(const AttributeList&) = delete;
// Explicit clone
AttributeList clone() const;

void push_back(Attribute i);

const Attribute* get(const char *name) const;
Attribute* get(const char *name) {
return const_cast<Attribute*>( const_cast<const AttributeList*>(this)->get(name));
}
bool has(const char *name) const {
return get(name) != 0;
}

friend ::std::ostream& operator<<(::std::ostream& os, const AttributeList& x) {
for(const auto& i : x.m_items) {
os << "#[" << i << "]";
}
return os;
}
};


TAGGED_UNION(AttributeData, None,
(None, struct {}),
(String, struct {
Expand All @@ -70,7 +27,6 @@ TAGGED_UNION(AttributeData, None,
// - A parenthesised token tree
// > In 1.19 this was actually just sub-attributes
// - an associated (string) literal

class Attribute
{
Span m_span;
Expand Down Expand Up @@ -151,6 +107,46 @@ class Attribute
}
};


/// A list of attributes on an item (searchable by the attribute name)
class AttributeList
{
public:
::std::vector<Attribute> m_items;

AttributeList() {}
AttributeList(::std::vector<Attribute> items):
m_items( mv$(items) )
{
}

// Move present
AttributeList(AttributeList&&) = default;
AttributeList& operator=(AttributeList&&) = default;
// No copy assign, but explicit copy
explicit AttributeList(const AttributeList&) = default;
AttributeList& operator=(const AttributeList&) = delete;
// Explicit clone
AttributeList clone() const;

void push_back(Attribute i);

const Attribute* get(const char *name) const;
Attribute* get(const char *name) {
return const_cast<Attribute*>( const_cast<const AttributeList*>(this)->get(name));
}
bool has(const char *name) const {
return get(name) != 0;
}

friend ::std::ostream& operator<<(::std::ostream& os, const AttributeList& x) {
for(const auto& i : x.m_items) {
os << "#[" << i << "]";
}
return os;
}
};

} // namespace AST

#endif
Expand Down
15 changes: 8 additions & 7 deletions src/include/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

#include <string>

extern unsigned int giVersion_Major;
extern unsigned int giVersion_Minor;
extern unsigned int giVersion_Patch;
extern const char* gsVersion_GitHash;
extern const char* gsVersion_GitShortHash;
extern const char* gsVersion_BuildTime;
extern bool gbVersion_GitDirty;
extern const unsigned int giVersion_Major;
extern const unsigned int giVersion_Minor;
extern const unsigned int giVersion_Patch;
extern const bool gbVersion_GitDirty;
extern const char gsVersion_GitHash[];
extern const char gsVersion_GitShortHash[];
extern const char gsVersion_GitBranch[];
extern const char gsVersion_BuildTime[];

extern ::std::string Version_GetString();
161 changes: 161 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
zdep = dependency('zlib', fallback: ['zlib', 'zlib_dep'])

mrustc_includes = include_directories(
'include',
'.',

'parse',

'expand',
'macro_rules',

'ast',

'resolve',
'hir',
'hir_conv',
'hir_typeck',
'hir_expand',

'mir',

'trans',
)

version = custom_target(
'version',
input: 'version.py',
output: 'version.cpp',
build_always_stale: true,
install: false,
command: [
python, '@INPUT@',
'--output-file', '@OUTPUT@',
'--major-version', major_version.to_string(),
'--minor-version', minor_version.to_string(),
'--patch-version', patch_version.to_string(),
],
)
version_cpp = version[0]

mrustc_exe = executable(
'mrustc',
'debug.cpp',
'main.cpp',
'ident.cpp',
'span.cpp',
'rc_string.cpp',
version_cpp,

'parse/root.cpp',
'parse/types.cpp',
'parse/tokentree.cpp',
'parse/pattern.cpp',
'parse/paths.cpp',
'parse/ttstream.cpp',
'parse/token.cpp',
'parse/ttstream.hpp',
'parse/expr.cpp',
'parse/lex.cpp',
'parse/interpolated_fragment.cpp',
'parse/parseerror.cpp',
'parse/tokenstream.cpp',

'expand/crate_tags.cpp',
'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/rustc_diagnostics.cpp',
'macro_rules/parse.cpp',
'macro_rules/mod.cpp',
'macro_rules/eval.cpp',

'ast/types.cpp',
'ast/dump.cpp',
'ast/crate.cpp',
'ast/pattern.cpp',
'ast/expr.cpp',
'ast/path.cpp',
'ast/ast.cpp',

'resolve/absolute.cpp',
'resolve/use.cpp',
'resolve/index.cpp',
'hir/generic_params.cpp',
'hir/type.cpp',
'hir/crate_post_load.cpp',
'hir/dump.cpp',
'hir/hir.cpp',
'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.cpp',
'hir/path.cpp',
'hir/deserialise.cpp',
'hir/from_ast_expr.cpp',
'hir_conv/bind.cpp',
'hir_conv/expand_type.cpp',
'hir_conv/resolve_ufcs.cpp',
'hir_conv/markings.cpp',
'hir_conv/constant_evaluation.cpp',
'hir_expand/erased_types.cpp',
'hir_expand/closures.cpp',
'hir_expand/annotate_value_usage.cpp',
'hir_expand/vtable.cpp',
'hir_expand/ufcs_everything.cpp',
'hir_expand/reborrow.cpp',
'hir_typeck/helpers.cpp',
'hir_typeck/expr_visit.cpp',
'hir_typeck/expr_check.cpp',
'hir_typeck/expr_cs.cpp',
'hir_typeck/impl_ref.cpp',
'hir_typeck/static.cpp',
'hir_typeck/outer.cpp',
'hir_typeck/common.cpp',

'mir/check_full.cpp',
'mir/helpers.cpp',
'mir/optimise.cpp',
'mir/mir.cpp',
'mir/dump.cpp',
'mir/visit_crate_mir.cpp',
'mir/mir_builder.cpp',
'mir/from_hir_match.cpp',
'mir/cleanup.cpp',
'mir/check.cpp',
'mir/from_hir.cpp',
'mir/mir_ptr.cpp',

'trans/enumerate.cpp',
'trans/codegen.cpp',
'trans/monomorphise.hpp',
'trans/mangling.cpp',
'trans/target.cpp',
'trans/trans_list.cpp',
'trans/codegen_mmir.cpp',
'trans/monomorphise.cpp',
'trans/allocator.cpp',
'trans/codegen_c.cpp',
'trans/codegen_c_structured.cpp',

include_directories: mrustc_includes,
dependencies: [zdep, common],
)
8 changes: 8 additions & 0 deletions src/mir/from_hir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ struct SplitArm {
//BasicBlockId source_block;
::std::map<unsigned int, VarState> states;
::std::map<unsigned int, VarState> arg_states;

SplitArm(const SplitArm&) = delete;
SplitArm(SplitArm&&) = default;

SplitArm& operator=(const SplitArm&) = delete;
SplitArm& operator=(SplitArm&&) = default;

~SplitArm() = default;
};
struct SplitEnd {
::std::map<unsigned int, VarState> states;
Expand Down
Loading