Page MenuHomeDevCentral

D2393.id6057.diff
No OneTemporary

D2393.id6057.diff

diff --git a/_modules/rust.py b/_modules/rust.py
new file mode 100755
--- /dev/null
+++ b/_modules/rust.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+
+# -------------------------------------------------------------
+# Salt — Rust module
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Description: Provide support for Rust properties
+# License: BSD-2-Clause
+# -------------------------------------------------------------
+
+
+from salt.utils.path import which as path_which
+
+
+def __virtual__():
+ """
+ Only load if the Rust compiler is available
+ """
+ return path_which('rustc') is not None,\
+ "The Rust execution module cannot be loaded: rustc not installed."
+
+
+def get_rustc_triplet():
+ """
+ A function to get a node triplet for Rust toolchains.
+
+ CLI Example:
+
+ salt * rust.get_rustc_triplet
+ """
+
+ # Thanks to @semarie for that tip.
+ return __salt__['cmd.shell']("rustc -vV | sed -ne 's/^host: //p'")
diff --git a/_tests/modules/test_rust.py b/_tests/modules/test_rust.py
new file mode 100755
--- /dev/null
+++ b/_tests/modules/test_rust.py
@@ -0,0 +1,14 @@
+from importlib.machinery import SourceFileLoader
+import unittest
+
+
+salt_test_case = SourceFileLoader('salt_test_case', "salt_test_case.py").load_module()
+rust = SourceFileLoader('rust', "../_modules/rust.py").load_module()
+
+
+class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase):
+
+ def test_get_rustc_triplet(self):
+ triplet = rust.get_rustc_triplet()
+
+ self.assertTrue(len(triplet.split("-")) > 2)
diff --git a/pillar/core/users.sls b/pillar/core/users.sls
--- a/pillar/core/users.sls
+++ b/pillar/core/users.sls
@@ -117,6 +117,8 @@
devserver_tasks:
- deploy_dotfiles
- deploy_nanotab
+ - install_rustup
+ - install_diesel
uid: 5001
erol:
diff --git a/roles/devserver/userland-home/homefiles.sls b/roles/devserver/userland-home/homefiles.sls
--- a/roles/devserver/userland-home/homefiles.sls
+++ b/roles/devserver/userland-home/homefiles.sls
@@ -7,6 +7,7 @@
# -------------------------------------------------------------
{% from "map.jinja" import dirs with context %}
+{% set triplet = salt['rust.get_rustc_triplet']() %}
{% for username, user in salt['forest.get_users']().items() %}
{% set tasks = user.get('devserver_tasks', []) %}
@@ -37,4 +38,21 @@
- unset tabstospaces
{% endif %}
+{% if 'install_rustup' in tasks %}
+{% for toolchain in ['stable', 'nightly'] %}
+devserver_rustup_{{toolchain}}_{{username}}:
+ cmd.run:
+ - name: rustup install {{ toolchain }}
+ - runas: {{ username }}
+ - creates: /home/{{ username }}/.rustup/toolchains/{{ toolchain }}-{{ triplet }}
+{% endfor %}
+{% endif %}
+
+{% if 'install_diesel' in tasks %}
+devserver_diesel_{{username}}:
+ cmd.run:
+ - name: cargo install diesel_cli --no-default-features --features postgres,sqlite
+ - creates: /home/{{username}}/.cargo/bin/diesel
+{% endif %}
+
{% endfor %}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 16, 11:34 (20 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2247480
Default Alt Text
D2393.id6057.diff (3 KB)

Event Timeline