Browse Source

start of install program

Steven Schveighoffer 3 years ago
parent
commit
54b00903d8
4 changed files with 124 additions and 0 deletions
  1. 1 0
      example/source/app.d
  2. 15 0
      install/.gitignore
  3. 13 0
      install/dub.json
  4. 95 0
      install/source/app.d

+ 1 - 0
example/source/app.d

@@ -5,6 +5,7 @@ import raylib;
 void main()
 {
   writeln("Starting a raylib example.");
+  validateRaylibBinding();
 
   SetTargetFPS(60);
   InitWindow(800, 640, "Hello, World!");

+ 15 - 0
install/.gitignore

@@ -0,0 +1,15 @@
+.dub
+docs.json
+__dummy.html
+docs/
+/install
+install.so
+install.dylib
+install.dll
+install.a
+install.lib
+install-test-*
+*.exe
+*.o
+*.obj
+*.lst

+ 13 - 0
install/dub.json

@@ -0,0 +1,13 @@
+{
+	"authors": [
+		"Steven Schveighoffer"
+	],
+	"copyright": "Copyright © 2022, Steven Schveighoffer",
+	"dependencies": {
+		"argparse": "~>1.1.1",
+		"jsoniopipe": "~>0.1.4"
+	},
+	"description": "Install raylib binary files",
+	"license": "boost-1.0",
+	"name": "install"
+}

+ 95 - 0
install/source/app.d

@@ -0,0 +1,95 @@
+import std.stdio;
+import std.file;
+import std.path;
+import std.compiler;
+import std.system;
+import std.format;
+import std.conv;
+import argparse;
+import std.process;
+import iopipe.json.serialize;
+import iopipe.json.parser;
+import std.exception;
+import iopipe.traits;
+
+version(X86)
+	enum arch="x86";
+else version(X86_64)
+	enum arch="x86_64";
+else version(ARM)
+	enum arch="arm";
+else version(AArch64)
+	enum arch="arm64";
+else
+	static assert(false, "Unsupported architecture");
+
+// establish the runtime
+version(CRuntime_Microsoft)
+	enum CRT="MSVC";
+else version(CRuntime_Glibc)
+	enum CRT="glibc";
+else version(CppRuntime_Clang)
+	enum CRT="llvm";
+else
+	static assert(false, "Unsupported runtime");
+@(Command("install").Description("Install the raylib-d binary C libraries to a location that can be used for linking"))
+struct Args {
+	@(NamedArgument().Description("Copy libraries to the local directory"))
+	bool local;
+}
+
+enum baseDir = buildPath("install", "lib", os.to!string, arch.to!string, CRT.to!string);
+
+int realMain(Args args)
+{
+    writeln("raylib-d library installation");
+    // look at the dub.selections.json file
+    auto dubConfig = execute(["dub", "describe"]);
+    string raylibdPath;
+    if(dubConfig.status != 0)
+    {
+        stderr.writeln("Error executing dub describe: ", dubConfig.output);
+        return dubConfig.status;
+    }
+    char[] getRaylibPath(char[] jsonStr)
+    {
+        auto tokens = jsonTokenizer(jsonStr);
+        enforce(tokens.parseTo("packages"), "Could not find packages in dub json output!");
+        auto nt = tokens.next.token;
+        enforce(nt == JSONToken.ArrayStart, "Expected array start in packages");
+        while(nt != JSONToken.ArrayEnd)
+        {
+            tokens.releaseParsed();
+            tokens.startCache;
+            enforce(tokens.parseTo("name"), "Could not find package name in json file");
+            auto n = tokens.next;
+            jsonExpect(n, JSONToken.String, "Expected string for package name");
+            if(n.data(tokens.chain) == "raylib-d")
+            {
+                tokens.rewind;
+                tokens.parseTo("path");
+                auto p = tokens.next;
+                jsonExpect(p, JSONToken.String, "Expected string for path");
+                return p.data(tokens.chain);
+            }
+            tokens.rewind;
+            tokens.endCache;
+            nt = tokens.skipItem.token;
+        }
+        throw new Exception("Could not find raylib-d dependency for current project!");
+    }
+    try {
+        auto path = getRaylibPath(dubConfig.output.dup);
+        auto libpath = buildPath(path, baseDir);
+        foreach(ent; dirEntries(libpath, SpanMode.shallow))
+        {
+            copy(ent.name, buildPath(".", ent.name.baseName));
+        }
+    } catch(Exception ex) {
+        stderr.writeln("Error: ", ex.msg);
+        return 1;
+    }
+    return 0;
+}
+
+mixin CLI!Args.main!realMain;