Skip to content

Commit dcd76fd

Browse files
committed
Add support for Rust code in DDNet
The glue is done using the [cxx crate](https://cxx.rs/) on the Rust side. As a proof-of-concept, only a small console command (`rust_version`) printing the currently used Rust version was added. You can generate and open the Rust documentation using `DDNET_TEST_NO_LINK=1 cargo doc --open`. You can run the Rust tests using `cmake --build <build dir> --target run_rust_tests`, they're automatically included in the `run_tests` target as well. Rust tests don't work on Windows in debug mode on Windows because Rust cannot currently link with the debug version of the C stdlib on Windows: rust-lang/rust#39016. --- The stuff in `src/rust-bridge` is generated using ``` cxxbridge src/engine/shared/rust_version.rs --output src/rust-bridge/engine/shared/rust_version.cpp --output src/rust-bridge/engine/shared/rust_version.h cxxbridge src/engine/console.rs --output src/rust-bridge/cpp/console.cpp --output src/rust-bridge/cpp/console.h ```
1 parent 1b114b2 commit dcd76fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1915
-62
lines changed

.cargo/config.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.'cfg(target_env = "msvc")']
2+
rustflags = ["-C", "target-feature=+crt-static"]

.github/workflows/build.yaml

+6-15
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ jobs:
2525
cmake-path: /usr/bin/
2626
cmake-args: -G Ninja -DTEST_MYSQL=ON
2727
cmake-init-env: CXXFLAGS=-Werror
28+
gtest-env: GTEST_FILTER=-*SQLite*
2829
package-file: "*-linux_x86_64.tar.xz"
2930
fancy: false
30-
env:
31-
GTEST_FILTER: -*SQLite*
3231
- os: macOS-latest
3332
cmake-args: -G Ninja
3433
cmake-init-env: CXXFLAGS=-Werror
@@ -55,6 +54,7 @@ jobs:
5554
- name: Prepare Linux (non-fancy)
5655
if: ${{ contains(matrix.os, 'ubuntu') && !matrix.fancy }}
5756
run: |
57+
rustup default 1.48.0
5858
sudo rm -rf /var/lib/mysql/ /var/run/mysqld
5959
sudo mkdir /var/lib/mysql/ /var/run/mysqld/
6060
sudo chown mysql:mysql /var/lib/mysql/ /var/run/mysqld/
@@ -93,48 +93,41 @@ jobs:
9393
sudo rm -rf /Library/Developer/CommandLineTools
9494
9595
- name: Build in debug mode
96-
env: ${{ matrix.env }}
9796
run: |
9897
mkdir debug
9998
cd debug
10099
${{ matrix.cmake-path }}cmake -E env ${{ matrix.cmake-init-env }} ${{ matrix.cmake-path }}cmake ${{ matrix.cmake-args }} -DCMAKE_BUILD_TYPE=Debug -Werror=dev -DDOWNLOAD_GTEST=ON -DDEV=ON -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG=. ..
101100
${{ matrix.cmake-path }}cmake --build . --config Debug --target everything ${{ matrix.build-args }}
102101
103102
- name: Test debug
104-
env: ${{ matrix.env }}
105103
run: |
106104
cd debug
107-
${{ matrix.cmake-path }}cmake --build . --config Debug --target run_tests ${{ matrix.build-args }}
105+
${{ matrix.cmake-path }}cmake -E env ${{ matrix.gtest-env }} ${{ matrix.cmake-path }}cmake --build . --config Debug --target run_tests ${{ matrix.build-args }}
108106
109107
- name: Run debug server
110-
env: ${{ matrix.env }}
111108
run: |
112109
cd debug
113110
./DDNet-Server shutdown
114111
115112
- name: Build in release mode
116-
env: ${{ matrix.env }}
117113
run: |
118114
mkdir release
119115
cd release
120116
${{ matrix.cmake-path }}cmake -E env ${{ matrix.cmake-init-env }} ${{ matrix.cmake-path }}cmake ${{ matrix.cmake-args }} -DCMAKE_BUILD_TYPE=Release -Werror=dev -DDOWNLOAD_GTEST=ON -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. ..
121117
${{ matrix.cmake-path }}cmake --build . --config Release --target everything ${{ matrix.build-args }}
122118
123119
- name: Test release
124-
env: ${{ matrix.env }}
125120
run: |
126121
cd release
127-
${{ matrix.cmake-path }}cmake --build . --config Release --target run_tests ${{ matrix.build-args }}
122+
${{ matrix.cmake-path }}cmake -E env ${{ matrix.gtest-env }} ${{ matrix.cmake-path }}cmake --build . --config Release --target run_tests ${{ matrix.build-args }}
128123
129124
- name: Run release server
130-
env: ${{ matrix.env }}
131125
run: |
132126
cd release
133127
./DDNet-Server shutdown
134128
135129
- name: Build headless client
136130
if: contains(matrix.os, 'ubuntu-latest')
137-
env: ${{ matrix.env }}
138131
run: |
139132
mkdir headless
140133
cd headless
@@ -178,7 +171,6 @@ jobs:
178171

179172
- name: Build in release mode with debug info and all features on
180173
if: matrix.fancy
181-
env: ${{ matrix.env }}
182174
run: |
183175
mkdir fancy
184176
cd fancy
@@ -187,14 +179,13 @@ jobs:
187179
188180
- name: Test fancy
189181
if: matrix.fancy
190-
env: ${{ matrix.env }}
191182
run: |
183+
find /usr/lib/ -name '*libwebsockets*'
192184
cd fancy
193-
${{ matrix.cmake-path }}cmake --build . --config RelWithDebInfo --target run_tests ${{ matrix.build-args }}
185+
${{ matrix.cmake-path }}cmake -E env ${{ matrix.gtest-env }} ${{ matrix.cmake-path }}cmake --build . --config RelWithDebInfo --target run_tests ${{ matrix.build-args }}
194186
195187
- name: Run fancy server
196188
if: matrix.fancy
197-
env: ${{ matrix.env }}
198189
run: |
199190
cd fancy
200191
./DDNet-Server shutdown

.github/workflows/rust.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Check Rust
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- staging.tmp
7+
- trying.tmp
8+
- staging-squash-merge.tmp
9+
pull_request:
10+
11+
jobs:
12+
rustdoc:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Run Rustdoc
17+
run: |
18+
RUSTDOCFLAGS=-Dwarnings DDNET_TEST_NO_LINK=1 cargo doc
19+
20+
rustfmt:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v2
24+
- name: Run Rustfmt
25+
run:
26+
cargo fmt -- --check
27+
28+
cargo-deny:
29+
runs-on: ubuntu-latest
30+
strategy:
31+
matrix:
32+
checks:
33+
- advisories
34+
- bans licenses sources
35+
36+
continue-on-error: ${{ matrix.checks == 'advisories' }}
37+
38+
steps:
39+
- uses: actions/checkout@v2
40+
- uses: EmbarkStudios/cargo-deny-action@v1
41+
with:
42+
command: check ${{ matrix.checks }}

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ bundle/
1111
.DS_Store
1212
.ninja_deps
1313
.ninja_log
14+
CACHEDIR.TAG
1415
CMakeCache.txt
1516
CMakeFiles
1617
CMakeSettings*
@@ -20,10 +21,12 @@ CTestTestfile.cmake
2021
Debug
2122
Makefile
2223
Release
24+
SAN.*
2325
_CPack_Packages/
2426
build.ninja
2527
checksummed_*
2628
cmake_install.cmake
29+
debug
2730
gmock.pc
2831
gmock_main.pc
2932
googletest-build/
@@ -34,8 +37,8 @@ gtest_main.pc
3437
install_manifest*.txt
3538
ninja_package
3639
pack_*/
40+
release
3741
rules.ninja
38-
SAN.*
3942
testrunner\[1\]_include.cmake
4043
vulkan_shaders_sha256.txt
4144

0 commit comments

Comments
 (0)