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:
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
- Main File: Place your main Rust file, such as
main.rs, inside thesrcdirectory. This file is the entry point to your application. - Dependencies: Include a
Cargo.tomlfile in your project root. This file should list all dependencies needed for your project. After defining yourCargo.toml, runningcargo buildwill generate atargetdirectory and aCargo.lockfile, ensuring consistent builds. - Compilation: Compile your project using
cargo build --releaseto generate the executable in thetarget/releasedirectory. For uploading, you only need the executable file, not the entiretargetdirectory.
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:
- Navigate to Code Upload: Access the code upload section by creating a new function.
- Choose File: Select your packaged file containing the compiled binary and
run.shscript. - Select Language: Choose Rust as the language.
- Specify Entry Point: The entry point is defined in your
Cargo.tomland implemented insrc/main.rs. Ensure your Rust binary is correctly referenced inrun.sh. - Upload: Submit your package for processing.
By following these steps, your Rust application will be correctly packaged and configured for deployment on the platform.