Skip to content

Other

Selecting Your Language

Concerning Other section let's try with Rust program. Confirm that your project is developed in Rust.

Here is an example Rust Sample

Create the run.sh Script (Optionnal)

Even though Rust applications compile to a binary, you can still use a run.sh script to execute the binary within the correct environment. The script should look something like this:

#!/bin/sh

set -euf

cd /opt/code
./your_executable_name

Replace your_executable_name with the name of the binary produced by compiling your Rust project.

Structuring Your Project

Here’s a sample structure for a Rust project ready for packaging:

my_rust_project/
├── src/
│   └── main.rs  # Your main application file.
├── Cargo.toml  # Describes your project and its dependencies.
├── Cargo.lock  # Ensures consistent builds.
└── run.sh
  1. Main File: Place your main Rust file, such as main.rs, inside the src directory. This file is the entry point to your application.
  2. Dependencies: Include a Cargo.toml file in your project root. This file should list all dependencies needed for your project. After defining your Cargo.toml, running cargo build will generate a target directory and a Cargo.lock file, ensuring consistent builds.
  3. Compilation: Compile your project using cargo build --release to generate the executable in the target/release directory. For uploading, you only need the executable file, not the entire target directory.

Defining the Entry Point

For Rust projects, the entry point is the main function in the src/main.rs file.

Example Code

Your Rust application might look like this:

use std::io::prelude::*;
use std::net::TcpListener;
use std::net::TcpStream;

fn main() {
    let listener = TcpListener::bind("0.0.0.0:8080").unwrap();
    println!("Running on 0.0.0.0:8080");
    for stream in listener.incoming() {
        let stream = stream.unwrap();
        handle_connection(stream);
    }
}

fn handle_connection(mut stream: TcpStream) {
    println!("handling connection");

    const MSG: &str = "helloworld";
    let response = format!("{:x?}", MSG.as_bytes());

    let mut buffer = [0; 1024];
    stream.read(&mut buffer).unwrap();

    let response = format!("HTTP/1.1 200 OK\nContent-Type: text/plain\n\nOKIDOK\n{}", response);
    stream.write(response.as_bytes()).unwrap();
    stream.flush().unwrap();
}

Uploading Your Code

To upload your Rust application to the platform, follow these steps:

  1. Navigate to Code Upload: Access the code upload section by creating a new function.
  2. Choose File: Select your packaged file containing the compiled binary and run.sh script.
  3. Select Language: Choose Rust as the language.
  4. Specify Entry Point: The entry point is defined in your Cargo.toml and implemented in src/main.rs. Ensure your Rust binary is correctly referenced in run.sh.
  5. Upload: Submit your package for processing.

By following these steps, your Rust application will be correctly packaged and configured for deployment on the platform.