-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Arker123/add-rust-samples-versions
add samples Rust 1.56-1.70, 32 and 64 bit
- Loading branch information
Showing
5 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Test Files for Rust Binary Versions | ||
|
||
This repository contains two ZIP archives, each containing compiled Rust binaries for minor versions 1.56.0 to 1.70.0, specifically for the 386 and amd64 architectures, along with their source code. | ||
|
||
## Contents | ||
|
||
Each ZIP archive corresponds to a specific architecture and contains the following files: | ||
|
||
- `bin/versions_32.zip`: Zip file containing the compiled Rust binaries for the 386 architecture. | ||
- `bin/versions_64.zip`: Zip file containing the compiled Rust binaries for the amd64 architecture. | ||
- `src/main.rs`: Source code for the binaries. | ||
|
||
## Generating Rust Binaries using Docker | ||
|
||
To automate the process of generating Rust binaries for all versions from 1.56.0 to 1.70.0 using Docker, you can use the provided Python script. Follow the steps below: | ||
|
||
- Make sure Docker is installed and properly configured on your system. | ||
- Run the script using the following command: `python3 rust_binary_generator.py`. | ||
|
||
The script will handle the setup, compilation, and generation of Rust binaries for the specified minor versions. The resulting binaries will be saved in the `bin/` directory. |
Binary file not shown.
Binary file not shown.
85 changes: 85 additions & 0 deletions
85
language/rust/rust-binaries-all-versions/rust_binary_generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright (C) 2023 Mandiant, Inc. All Rights Reserved. | ||
""" | ||
This Python script automates the process of generating Rust binaries for versions 1.56.0 to 1.70.0 using Docker. By leveraging Docker containers, it ensures a consistent and reproducible environment for compiling the Rust source code across different platforms. | ||
Please note that Docker must be installed and properly configured on your system for the script to execute successfully. | ||
Usage: | ||
python rust_binary_generator.py | ||
The resulting binaries will be saved in the `bin/` directory. | ||
""" | ||
|
||
import subprocess | ||
|
||
rust_versions = """ | ||
1.70.0 | ||
1.68.0 | ||
1.66.0 | ||
1.64.0 | ||
1.62.0 | ||
1.60.0 | ||
1.58.0 | ||
1.56.0 | ||
""" | ||
|
||
f = open("docker-compose.yml", "w") | ||
|
||
f.write( | ||
"""services: | ||
app: | ||
build: .""" | ||
) | ||
|
||
f.close() | ||
|
||
subprocess.call(["docker", "compose", "up"]) | ||
print("Compose is UP") | ||
|
||
architecture = {"386": "i686-pc-windows-gnu", "amd64": "x86_64-pc-windows-gnu"} | ||
|
||
for arch in architecture.keys(): | ||
for version in rust_versions.split(): | ||
print("version: ", version) | ||
|
||
f = open("Dockerfile", "w") | ||
|
||
target = architecture[arch] | ||
|
||
f.write( | ||
"""# syntax=docker/dockerfile:1 | ||
FROM rust:{} | ||
ENV USER root | ||
RUN cargo new known_binary | ||
WORKDIR known_binary | ||
COPY ./src/main.rs ./src/main.rs | ||
RUN apt update && apt install mingw-w64 -y | ||
RUN rustup target add {} | ||
RUN rustup update | ||
RUN cargo build --release --target {} | ||
""".format( | ||
version, target, target | ||
) | ||
) | ||
f.close() | ||
|
||
subprocess.call(["docker", "build", "--tag", "rust-test", "."]) | ||
subprocess.call( | ||
[ | ||
"docker", | ||
"run", | ||
"-v", | ||
".:/var/opt", | ||
"rust-test", | ||
"mv", | ||
"./target/{}/release/known_binary.exe".format(target), | ||
"/var/opt/bin/rust_{}_{}.exe".format(arch, version), | ||
] | ||
) | ||
|
||
subprocess.call(["docker", "compose", "down"]) | ||
print("Compose is DOWN") | ||
|
||
# Free up disk space | ||
subprocess.call(["docker", "system", "prune", "-a", "-f"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
fn main() { | ||
// (all the type annotations are superfluous) | ||
// A reference to a string allocated in read only memory | ||
let pangram: &'static str = "the quick brown fox jumps over the lazy dog"; | ||
println!("Pangram: {}", pangram); | ||
|
||
// Iterate over words in reverse, no new string is allocated | ||
println!("Words in reverse"); | ||
for word in pangram.split_whitespace().rev() { | ||
println!("> {}", word); | ||
} | ||
|
||
// Copy chars into a vector, sort and remove duplicates | ||
let mut chars: Vec<char> = pangram.chars().collect(); | ||
chars.sort(); | ||
chars.dedup(); | ||
|
||
// Create an empty and growable `String` | ||
let mut string = String::new(); | ||
for c in chars { | ||
// Insert a char at the end of string | ||
string.push(c); | ||
// Insert a string at the end of string | ||
string.push_str(", "); | ||
} | ||
|
||
// The trimmed string is a slice to the original string, hence no new | ||
// allocation is performed | ||
let chars_to_trim: &[char] = &[' ', ',']; | ||
let trimmed_str: &str = string.trim_matches(chars_to_trim); | ||
println!("Used characters: {}", trimmed_str); | ||
|
||
// Heap allocate a string | ||
let alice = String::from("I like dogs"); | ||
// Allocate new memory and store the modified string there | ||
let bob: String = alice.replace("dog", "cat"); | ||
|
||
println!("Alice says: {}", alice); | ||
println!("Bob says: {}", bob); | ||
} |