Browse Source

Some more hacks but it works-ish

Getty Ritter 4 years ago
parent
commit
475317675f
5 changed files with 36 additions and 29 deletions
  1. 1 1
      build_rust.sh
  2. 18 2
      meson.build
  3. 2 2
      rust/Cargo.toml
  4. 2 2
      rust/src/util.rs
  5. 13 22
      util.cpp

+ 1 - 1
build_rust.sh

@@ -5,5 +5,5 @@ DIR="$(pwd)"
     cd "$1/rust"
     cargo build --release
     echo "Copying to $DIR"
-    cp target/release/libslim.a "$DIR/libslim.a"
+    cp target/release/libslimrs.a "$DIR/libslimrs.a"
 )

+ 18 - 2
meson.build

@@ -40,7 +40,7 @@ use_pam = true
 build_rust = find_program('build_rust.sh')
 rusty = custom_target(
   'rusty',
-  output: ['libslim.a'],
+  output: ['libslimrs.a'],
   command: [build_rust, meson.current_source_dir()],
 )
 
@@ -48,6 +48,8 @@ cc = meson.get_compiler('cpp')
 deps = [
   cc.find_library('m'),
   cc.find_library('crypt'),
+  cc.find_library('pthread'),
+  cc.find_library('dl'),
   dependency('freetype2'),
   dependency('x11'),
   dependency('xmu'),
@@ -88,7 +90,21 @@ endif
 # #Set the custom CMake module directory where our include/lib finders are
 # cmake_module_path = '${CMAKE_SOURCE_DIR}/cmake/modules'
 
-slim_exe = executable('slim', slim_srcs, dependencies: deps, include_directories: [include_directories('.')], link_with: [libslim_lib, rusty])
+# combine = find_program('combine.sh')
+# combined = custom_target(
+#   'combined',
+#   input: [rusty, libslim_lib],
+#   output: ['libcombined.a'],
+#   command: [combine, '@INPUT@'],
+# )
+
+slim_exe = executable(
+  'slim',
+  slim_srcs,
+  dependencies: deps,
+  include_directories: [include_directories('.')],
+  link_with: [rusty, libslim_lib],
+)
 
 # # Fontconfig
 # fontconfig_dir = cmake_module_path

+ 2 - 2
rust/Cargo.toml

@@ -1,10 +1,10 @@
 [package]
-name = "slim"
+name = "slimrs"
 version = "0.1.0"
 edition = "2018"
 
 [lib]
-crate-type = ["staticlib"]
+crate-type = ["staticlib", "dylib"]
 
 [dependencies]
 subprocess = "*"

+ 2 - 2
rust/src/util.rs

@@ -1,8 +1,8 @@
 use std::ffi::CStr;
-use std::os::raw::{c_char};
+use std::os::raw::{c_char, c_int};
 use std::io::Write;
 
-#[derive(Debug)] 
+#[derive(Debug)]
 enum Error {
     IOError { error: std::io::Error },
     StringError { error: std::str::Utf8Error },

+ 13 - 22
util.cpp

@@ -16,25 +16,16 @@
 
 #include "util.h"
 
+extern "C" bool rs_add_mcookie(const char*, const char*, const char*, const char*);
+
 /*
  * Adds the given cookie to the specified Xauthority file.
  * Returns true on success, false on fault.
  */
 bool Util::add_mcookie(const std::string &mcookie, const char *display,
-	const std::string &xauth_cmd, const std::string &authfile)
+        const std::string &xauth_cmd, const std::string &authfile)
 {
-	FILE *fp;
-	std::string cmd = xauth_cmd + " -f " + authfile + " -q";
-
-	fp = popen(cmd.c_str(), "w");
-	if (!fp)
-		return false;
-	fprintf(fp, "remove %s\n", display);
-	fprintf(fp, "add %s %s %s\n", display, ".", mcookie.c_str());
-	fprintf(fp, "exit\n");
-
-	pclose(fp);
-	return true;
+  return rs_add_mcookie(mcookie.c_str(), display, xauth_cmd.c_str(), authfile.c_str());
 }
 
 /*
@@ -43,12 +34,12 @@ bool Util::add_mcookie(const std::string &mcookie, const char *display,
  */
 void Util::srandom(unsigned long seed)
 {
-	::srandom(seed);
+        ::srandom(seed);
 }
 
 long Util::random(void)
 {
-	return ::random();
+        return ::random();
 }
 
 /*
@@ -57,13 +48,13 @@ long Util::random(void)
  */
 long Util::makeseed(void)
 {
-	struct timespec ts;
-	long pid = getpid();
-	long tm = time(NULL);
+        struct timespec ts;
+        long pid = getpid();
+        long tm = time(NULL);
 
-	if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
-		ts.tv_sec = ts.tv_nsec = 0;
-	}
+        if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
+                ts.tv_sec = ts.tv_nsec = 0;
+        }
 
-	return pid + tm + (ts.tv_sec ^ ts.tv_nsec);
+        return pid + tm + (ts.tv_sec ^ ts.tv_nsec);
 }