Page MenuHomeDevCentral

D2393.id6059.diff
No OneTemporary

D2393.id6059.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,7 @@
devserver_tasks:
- deploy_dotfiles
- deploy_nanotab
+ - install_rustup
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,14 @@
- 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 %}
+
{% endfor %}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 16, 12:07 (21 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2247511
Default Alt Text
D2393.id6059.diff (2 KB)

Event Timeline