CSC/ECE 517 Spring 2015/oss M1502 GVJ: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 30: Line 30:
The syntax for these dependencies is shown below.  
The syntax for these dependencies is shown below.  


<code>
<pre>
[dependency.crate_name] <br>
[dependency.crate_name]
git = "path_to_crate_git" <br>
git = "path_to_crate_git"
//other options <br>
//other options
</code>
</pre>


Other options that are particularly useful include the ability to choose branches and revisions. Each of these options are shown below.
Other options that are particularly useful include the ability to choose branches and revisions. Each of these options are shown below.


<code>
<pre>
branch = "name_of_branch" <br>
branch = "name_of_branch"
rev = "hash_of_commit" <br>
rev = "hash_of_commit"
</code>
</pre>




The next step for adding a crate to a servo project requires modifying the main.rs or lib.rs, depending on which is being used for the project. Normally, the main.rs is used for the primary package, where other parts of a project may only use a lib.rs. To add a crate in either of these files, use the code shown below.
The next step for adding a crate to a servo project requires modifying the main.rs or lib.rs, depending on which is being used for the project. Normally, the main.rs is used for the primary package, where other parts of a project may only use a lib.rs. To add a crate in either of these files, use the code shown below.


<code>
<pre>
extern crate crate_name <br>
extern crate crate_name
</code>
</pre>


Further uses of Cargo and other syntax beyond what is discussed in this article can be found here: [http://doc.crates.io/guide.html].
Further uses of Cargo and other syntax beyond what is discussed in this article can be found here: [http://doc.crates.io/guide.html].

Revision as of 20:11, 23 March 2015

M1502: Implementing the WebSocket API

This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.

Introduction to Mozilla Servo

Servo is a Web Browser engine written in Rust. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism.

Rust

Rust is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both.

WebSocket

WebSockets is a protocol that provides full-duplex channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The WebSocket specification defines an API to establish a "socket" connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.

Project Description

The goal of this project was to incorporate the websocket crate in to servo, using the up to date rust websocket crate instructions. To do that, Rust's crate manager and how it interacted with servo's Mach tool was explored.

The Crate Manager

To incorporate new crates in to a project in rust, two main tasks are needed. First, depending on the crate that is used, a dependency needs to be added to the relevant Cargo.toml. For servo and websocket, that Cargo.toml is related to the script component, found in servo's components/script folder. To add a dependency to the Cargo.toml file, a couple different methods are available, both with separate advantages.

The first method is the simplest, and allows specification of crate versions through a method similar to Ruby gemfiles. Simply navigate to the [dependencies] section of the Cargo.toml, and add the crate and the version, like this example with websocket:

[dependencies]
...
websocket = "0.11.0"

You can vary this with other options, like ~, as in Ruby, to specify that the latest crate should be loaded or an exact version.

The second method of adding a dependency allows for far more flexibility. A crate's git repository can be added directly to the Cargo.toml, as well as many options to use particular branches, versions, and revisions. The syntax for these dependencies is shown below.

[dependency.crate_name]
git = "path_to_crate_git"
//other options

Other options that are particularly useful include the ability to choose branches and revisions. Each of these options are shown below.

branch = "name_of_branch"
rev = "hash_of_commit"


The next step for adding a crate to a servo project requires modifying the main.rs or lib.rs, depending on which is being used for the project. Normally, the main.rs is used for the primary package, where other parts of a project may only use a lib.rs. To add a crate in either of these files, use the code shown below.

extern crate crate_name

Further uses of Cargo and other syntax beyond what is discussed in this article can be found here: [1].