diff --git a/bin/tessel-2.js b/bin/tessel-2.js index 642394ec..7dc8062a 100755 --- a/bin/tessel-2.js +++ b/bin/tessel-2.js @@ -203,8 +203,12 @@ makeCommand('run') default: false, help: 'Deploy a project containing all files within, including those not used by the program, excluding any files matched by non-negated rules in .tesselignore and including any files matched by rules in .tesselinclude. Program is started from specified file.' }) + .option('rustCC', { + default: 'localhost:8080', + help: 'Specify the location and port of the Rust cross-compilation server.' + }) .help(` - Deploy a script to Tessel and run it with Node. + Deploy a script to Tessel and run it. Assets that are not directly deployed as a dependency via require analysis, for example images or html files of an application (and their directories), diff --git a/lib/tessel/commands.js b/lib/tessel/commands.js index 8cfeb10d..a4d3521e 100644 --- a/lib/tessel/commands.js +++ b/lib/tessel/commands.js @@ -4,6 +4,8 @@ * Language: * * */ +var rust = require('deployment/rust') + module.exports.app = { // Note: These should be converted to method shorthand // once t2-cli moves to Node 6 @@ -22,7 +24,7 @@ module.exports.js = { }; module.exports.rs = { - execute: () => ['rust_executable'], + execute: () => [rust.BINARY_NAME], }; module.exports.py = { diff --git a/lib/tessel/deployment/rust.js b/lib/tessel/deployment/rust.js index 8f7f9ab8..0b6e3bc3 100644 --- a/lib/tessel/deployment/rust.js +++ b/lib/tessel/deployment/rust.js @@ -13,18 +13,19 @@ var tar = require('tar'); var tarStream = require('tar-stream'); var streamToArray = require('stream-to-array'); - // Internal var commands = require('../commands'); var lists = require('./lists/rust'); var Tessel = require('../tessel'); +var log = require('../../log'); +const BINARY_NAME = 'rust_executable' var exportables = { meta: { name: 'rust', extname: 'rs', - binary: 'rust_executable', + binary: BINARY_NAME, entry: 'src/main.rs', configuration: 'Cargo.toml', checkConfiguration: (pushdir, basename, program) => { @@ -43,7 +44,7 @@ var exportables = { shell: () => { return tags.stripIndent ` #!/bin/sh - exec /app/remote-script/rust_executable + exec /app/remote-script/${BINARY_NAME} `; }, }, @@ -54,11 +55,10 @@ exportables.preBundle = function() { return Promise.resolve(); }; -exportables.tarBundle = function() { - // This must implement a Promise that resolves with a Buffer - // that represents a DIRECTORY containing the compiled Rust - // executable. - +// This must implement a Promise that resolves with a Buffer +// that represents a DIRECTORY containing the compiled Rust +// executable. +exportables.tarBundle = function(opts) { return exportables.remoteRustCompilation(opts); }; @@ -67,7 +67,7 @@ exportables.tarBundle = function() { // include the parameter in the list. exportables.preRun = function(tessel, options) { // jshint ignore:line return new Promise((resolve) => { - return tessel.connection.exec(commands.chmod('+x', `${Tessel.REMOTE_RUN_PATH}rust_executable`), {}, () => resolve()); + return tessel.connection.exec(commands.chmod('+x', `${Tessel.REMOTE_RUN_PATH}${BINARY_NAME}`), {}, () => resolve()); }); }; @@ -77,31 +77,31 @@ exportables.postRun = function(tessel, options) { }; */ -exportables.remoteRustCompilation = function(project) { +exportables.remoteRustCompilation = function(opts) { log.info("Compiling Rust code..."); + log.info(opts) return new Promise(function(resolve, reject) { // Save our incoming compiled buffer to this array var buffers = []; // The location of our cross compilation server - // TODO: don't harcode this var post_options = { - host: '127.0.0.1', + host: opts.rustCC, port: '8080', path: '/rust-compile', method: 'POST', headers: { 'Content-Type': 'application/octet-stream', - 'X-BINARY-NAME': project.program, - 'X-PROJECT-FOLDER': path.basename(project.pushdir), + 'X-BINARY-NAME': 'hello', + 'X-PROJECT-FOLDER': path.basename(opts.target), } }; // Create a new tar pack for incoming executable data var pack = tarStream.pack(); // Create the entry file name - pack.entry( { name : 'rust_executable' }); + pack.entry( { name : 'BINARY_NAME' }); // Set up the request var post_req = http.request(post_options, function(res) { @@ -140,7 +140,7 @@ exportables.remoteRustCompilation = function(project) { .on('error', reject) // Send the project directory through the tar packer and into the post request - Reader({ path: project.pushdir, type: "Directory" }) + Reader({ path: opts.pushdir, type: "Directory" }) .on('error', reject) .pipe(outgoingPacker) .pipe(post_req)