Skip to content

Commit

Permalink
Adds simple, untested implementation of rust deploys
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyman727 committed Jul 13, 2016
1 parent e334d8e commit 3662940
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
80 changes: 79 additions & 1 deletion lib/tessel/deployment/rust.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
// System Objects
var path = require('path');
var http = require('http');
var path = require('path');

// Third Party Dependencies
var fs = require('fs-extra');
var tags = require('common-tags');
var toml = require('toml');
require('toml-require').install();
var Reader = require('fstream').Reader;
var tar = require('tar');
var tarStream = require('tar-stream');
var streamToArray = require('stream-to-array');


// Internal
Expand Down Expand Up @@ -51,7 +58,8 @@ exportables.tarBundle = function() {
// This must implement a Promise that resolves with a Buffer
// that represents a DIRECTORY containing the compiled Rust
// executable.
return Promise.resolve(new Buffer([0xFF]));

return exportables.remoteRustCompilation(opts);
};

// The following line will be ignored by JSHint because
Expand All @@ -69,4 +77,74 @@ exportables.postRun = function(tessel, options) {
};
*/

exportables.remoteRustCompilation = function(project) {
log.info("Compiling Rust code...");
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',
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),
}
};

// Create a new tar pack for incoming executable data
var pack = tarStream.pack();
// Create the entry file name
pack.entry( { name : 'rust_executable' });

// Set up the request
var post_req = http.request(post_options, function(res) {
// When we get incoming binary data, save to our buffers
res.on('data', function(chunk) {
// Write this incoming data to our tar packer
pack.write(chunk);
})
// Reject on failure
.on('error', function(e) {
return reject(e);
})
// When the post completes, resolve with the executable
.on('end', function() {
// Indicate that all data has been received
pack.finalize();

// Turn the stream into an array of buffers
return streamToArray(pack)
.then((arr) => {
// For each buffer in the array
for (var i = 0, l = arr.length; i < l ; ++i) {
// Grab the part
var part = parts[i]
// Push it into our buffer array
buffers.push((part instanceof Buffer) ? part : new Buffer(part))
}
// Resolve with concatenated buffers
return resolve(Buffer.concat(buffers));
})
})
});

// Create an outgoing tar packer for our project
var outgoingPacker = tar.Pack({ noProprietary: true })
.on('error', reject)

// Send the project directory through the tar packer and into the post request
Reader({ path: project.pushdir, type: "Directory" })
.on('error', reject)
.pipe(outgoingPacker)
.pipe(post_req)
});
}

module.exports = exportables;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@
"shell-escape": "^0.2.0",
"ssh2": "^0.4.2",
"sshpk": "^1.6.0",
"stream-to-array": "^2.3.0",
"stream-to-buffer": "^0.1.0",
"t2-project": "^0.3.0",
"tar": "^2.1.1",
"tar-stream": "^1.3.0",
"toml": "^2.3.0",
"toml-require": "^1.1.0",
"uglify-js": "^2.6.2",
"update-notifier": "^0.6.3",
"url-join": "0.0.1",
Expand Down

0 comments on commit 3662940

Please sign in to comment.