summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--src/include/version.hpp20
-rw-r--r--src/main.cpp7
-rw-r--r--src/version.cpp29
4 files changed, 61 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 256bb6c6..33509546 100644
--- a/Makefile
+++ b/Makefile
@@ -70,7 +70,7 @@ OBJDIR = .obj/
BIN := bin/mrustc$(EXESUF)
-OBJ := main.o
+OBJ := main.o version.o
OBJ += span.o rc_string.o debug.o ident.o
OBJ += ast/ast.o
OBJ += ast/types.o ast/crate.o ast/path.o ast/expr.o ast/pattern.o
@@ -314,6 +314,10 @@ $(OBJDIR)%.o: src/%.cpp
@mkdir -p $(dir $@)
@echo [CXX] -o $@
$V$(CXX) -o $@ -c $< $(CXXFLAGS) $(CPPFLAGS) -MMD -MP -MF $@.dep
+$(OBJDIR)version.o: $(OBJDIR)%.o: src/%.cpp $(filter-out $(OBJDIR)version.o,$(OBJ)) Makefile
+ @mkdir -p $(dir $@)
+ @echo [CXX] -o $@
+ $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 $$?)
src/main.cpp: $(PCHS:%=src/%.gch)
diff --git a/src/include/version.hpp b/src/include/version.hpp
new file mode 100644
index 00000000..2270a592
--- /dev/null
+++ b/src/include/version.hpp
@@ -0,0 +1,20 @@
+/*
+ * MRustC - Rust Compiler
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * version.hpp
+ * - Compiler version number
+ */
+#pragma once
+
+#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 ::std::string Version_GetString();
diff --git a/src/main.cpp b/src/main.cpp
index 8f2740fc..0e37f4a3 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -9,6 +9,7 @@
#include <iomanip>
#include <string>
#include <set>
+#include <version.hpp>
#include <string_view.hpp>
#include "parse/lex.hpp"
#include "parse/parseerror.hpp"
@@ -944,6 +945,12 @@ ProgramParams::ProgramParams(int argc, char *argv[])
this->show_help();
exit(0);
}
+ else if( strcmp(arg, "--version" ) == 0 ) {
+ ::std::cout << "MRustC " << Version_GetString() << ::std::endl;
+ ::std::cout << "- Build time: " << gsVersion_BuildTime << ::std::endl;
+ ::std::cout << "- Commit: " << gsVersion_GitHash << (gbVersion_GitDirty ? " (dirty tree)" : "") << ::std::endl;
+ exit(0);
+ }
// --out-dir <dir> >> Set the output directory for automatically-named files
else if( strcmp(arg, "--out-dir") == 0) {
if (i == argc - 1) {
diff --git a/src/version.cpp b/src/version.cpp
new file mode 100644
index 00000000..d6307618
--- /dev/null
+++ b/src/version.cpp
@@ -0,0 +1,29 @@
+/*
+ * MRustC - Rust Compiler
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * version.cpp
+ * - Compiler version number
+ */
+#include <version.hpp>
+#include <sstream>
+
+#define VERSION_MAJOR 0
+#define VERSION_MINOR 8
+#define VERSION_PATCH 0
+
+unsigned int giVersion_Major = VERSION_MAJOR;
+unsigned int giVersion_Minor = VERSION_MINOR;
+unsigned int giVersion_Patch = VERSION_PATCH;
+bool gbVersion_GitDirty = VERSION_GIT_ISDIRTY;
+const char* gsVersion_GitHash = VERSION_GIT_FULLHASH;
+const char* gsVersion_GitShortHash = VERSION_GIT_SHORTHASH;
+const char* gsVersion_BuildTime = VERSION_BUILDTIME;
+
+
+::std::string Version_GetString()
+{
+ ::std::stringstream ss;
+ ss << "v" << VERSION_MAJOR << "." << VERSION_MINOR << "." << VERSION_PATCH << " " << VERSION_GIT_BRANCH << ":" << VERSION_GIT_SHORTHASH;
+ return ss.str();
+}