Skip to content

Commit

Permalink
Removed rust_executable and added rustCC
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Lewis authored and johnnyman727 committed Jul 13, 2016
1 parent 3662940 commit ea00424
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
6 changes: 5 additions & 1 deletion bin/tessel-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion lib/tessel/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,7 +24,7 @@ module.exports.js = {
};

module.exports.rs = {
execute: () => ['rust_executable'],
execute: () => [rust.BINARY_NAME],
};

module.exports.py = {
Expand Down
32 changes: 16 additions & 16 deletions lib/tessel/deployment/rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -43,7 +44,7 @@ var exportables = {
shell: () => {
return tags.stripIndent `
#!/bin/sh
exec /app/remote-script/rust_executable
exec /app/remote-script/${BINARY_NAME}
`;
},
},
Expand All @@ -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);
};

Expand All @@ -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());
});
};

Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ea00424

Please sign in to comment.