Skip to content

Commit 11e3008

Browse files
authored
Cross Compiling Rust Code for Windows
Cross Compiling Rust Code for Windows using Docker.
1 parent b5325e6 commit 11e3008

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

docker.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Cross Compile Rust-Programs using Docker
2+
3+
## Prerequisites
4+
5+
* Docker
6+
7+
## Steps
8+
9+
I have created an Dockerfile in my main branch of [Rust-for-Malware-Development](https://github.com/Whitecat18/Rust-for-Malware-Development.git). lets build our image
10+
11+
12+
```
13+
docker build . -t windows_compile
14+
```
15+
16+
> ⚠️ : This build takes upto 3 GB Space
17+
18+
Next run the container in the following project Directory !
19+
20+
Once you’ve created the image, then you can run the container by executing the following command:
21+
22+
```
23+
docker run --rm -v ‘your-pwd’:/app rust_cross_compile/windows
24+
```
25+
26+
The -rm option will remove the container when the command completes. The -v command allows you to persist data after a container has existed by linking your container storage with your local machine. Replace ‘your-pwd’ with the absolute path to your Rust directory
27+
28+
Example i have compiled [EDRChecker](https://github.com/Whitecat18/Rust-for-Malware-Development/tree/main/EDRChecker) and executed on my Virtual Machine.
29+
30+
![image](https://github.com/user-attachments/assets/f36dd530-9da8-4e64-9180-078af6bfb37c)
31+
32+
![image](https://github.com/user-attachments/assets/57272c70-de5c-4435-acc8-7899c1ea7a7a)
33+
34+
35+
## Modifying Dockerfile
36+
37+
Here is the Default version of Rust Container
38+
```
39+
FROM rust:latest
40+
41+
RUN apt update ; apt upgrade -y
42+
RUN apt install -y g++-mingw-w64-x86-64
43+
44+
RUN rustup target add x86_64-pc-windows-gnu
45+
RUN rustup toolchain install stable-x86_64-pc-windows-gnu
46+
47+
WORKDIR /app
48+
49+
CMD ["cargo", "build", "--target", "x86_64-pc-windows-gnu"]
50+
```
51+
52+
For **--release** you can modify the Dockerfile as Follows
53+
54+
```
55+
FROM rust:latest
56+
57+
RUN apt update ; apt upgrade -y
58+
RUN apt install -y g++-mingw-w64-x86-64
59+
60+
RUN rustup target add x86_64-pc-windows-gnu
61+
RUN rustup toolchain install stable-x86_64-pc-windows-gnu
62+
63+
WORKDIR /app
64+
65+
CMD ["cargo", "build", "--target", "x86_64-pc-windows-gnu", "--release"]
66+
```
67+
68+
Here is the Image:
69+
70+
![image](https://github.com/user-attachments/assets/b1220909-c0c8-4645-b7a2-94acb5722bf6)
71+
72+
![image](https://github.com/user-attachments/assets/35efd900-2f61-4c7d-89d2-815ec318639e)
73+
74+
THE PATH WHERE IT COMPILES AND KEEPS BINARY FILES:
75+
76+
![image](https://github.com/user-attachments/assets/66fc1c4f-6759-413d-a417-3609d5bd14c2)
77+

0 commit comments

Comments
 (0)