Skip to content

Commit b21ba35

Browse files
Merge #5599
5599: Add support for Rust code in DDNet r=def- a=heinrich5991 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 ``` Co-authored-by: heinrich5991 <[email protected]>
2 parents 48d82e9 + dcd76fd commit b21ba35

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

+1923
-79
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

+14-32
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,26 @@ jobs:
1818
include:
1919
- os: ubuntu-latest
2020
cmake-args: -G Ninja
21+
cmake-init-env: CXXFLAGS=-Werror
2122
package-file: "*-linux_x86_64.tar.xz"
2223
fancy: true
23-
env:
24-
CFLAGS: -Wdeclaration-after-statement -Werror
25-
CXXFLAGS: -Werror
2624
- os: ubuntu-20.04
2725
cmake-path: /usr/bin/
2826
cmake-args: -G Ninja -DTEST_MYSQL=ON
27+
cmake-init-env: CXXFLAGS=-Werror
28+
gtest-env: GTEST_FILTER=-*SQLite*
2929
package-file: "*-linux_x86_64.tar.xz"
3030
fancy: false
31-
env:
32-
CFLAGS: -Wdeclaration-after-statement -Werror
33-
CXXFLAGS: -Werror
34-
GTEST_FILTER: -*SQLite*
3531
- os: macOS-latest
3632
cmake-args: -G Ninja
33+
cmake-init-env: CXXFLAGS=-Werror
3734
package-file: "*-macos.dmg"
3835
fancy: false
39-
env:
40-
CFLAGS: -Wdeclaration-after-statement -Werror
41-
CXXFLAGS: -Werror
4236
- os: windows-latest
4337
cmake-args: -A x64
38+
cmake-init-env: CXXFLAGS=/WX LDFLAGS=/WX
4439
package-file: "*-win64.zip"
4540
fancy: false
46-
env:
47-
CFLAGS: /WX
48-
CXXFLAGS: /WX
49-
LDFLAGS: /WX
5041

5142
steps:
5243
- uses: actions/checkout@v3
@@ -63,6 +54,7 @@ jobs:
6354
- name: Prepare Linux (non-fancy)
6455
if: ${{ contains(matrix.os, 'ubuntu') && !matrix.fancy }}
6556
run: |
57+
rustup default 1.48.0
6658
sudo rm -rf /var/lib/mysql/ /var/run/mysqld
6759
sudo mkdir /var/lib/mysql/ /var/run/mysqld/
6860
sudo chown mysql:mysql /var/lib/mysql/ /var/run/mysqld/
@@ -102,57 +94,49 @@ jobs:
10294
sudo rm -rf /Library/Developer/CommandLineTools
10395
10496
- name: Build in debug mode
105-
env: ${{ matrix.env }}
10697
run: |
10798
mkdir debug
10899
cd debug
109-
${{ matrix.cmake-path }}cmake --version
110-
${{ matrix.cmake-path }}cmake ${{ matrix.cmake-args }} -DCMAKE_BUILD_TYPE=Debug -Werror=dev -DDOWNLOAD_GTEST=ON -DDEV=ON -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG=. ..
100+
${{ 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=. ..
111101
${{ matrix.cmake-path }}cmake --build . --config Debug --target everything ${{ matrix.build-args }}
112102
113103
- name: Test debug
114-
env: ${{ matrix.env }}
115104
run: |
116105
cd debug
117-
${{ matrix.cmake-path }}cmake --build . --config Debug --target run_tests ${{ matrix.build-args }}
106+
${{ matrix.cmake-path }}cmake -E env ${{ matrix.gtest-env }} ${{ matrix.cmake-path }}cmake --build . --config Debug --target run_tests ${{ matrix.build-args }}
118107
119108
- name: Run debug server
120-
env: ${{ matrix.env }}
121109
run: |
122110
cd debug
123111
./DDNet-Server shutdown
124112
125113
- name: Build in release mode
126-
env: ${{ matrix.env }}
127114
run: |
128115
mkdir release
129116
cd release
130-
${{ matrix.cmake-path }}cmake ${{ matrix.cmake-args }} -DCMAKE_BUILD_TYPE=Release -Werror=dev -DDOWNLOAD_GTEST=ON -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. ..
117+
${{ 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=. ..
131118
${{ matrix.cmake-path }}cmake --build . --config Release --target everything ${{ matrix.build-args }}
132119
133120
- name: Test release
134-
env: ${{ matrix.env }}
135121
run: |
136122
cd release
137-
${{ matrix.cmake-path }}cmake --build . --config Release --target run_tests ${{ matrix.build-args }}
123+
${{ matrix.cmake-path }}cmake -E env ${{ matrix.gtest-env }} ${{ matrix.cmake-path }}cmake --build . --config Release --target run_tests ${{ matrix.build-args }}
138124
139125
- name: Run release server
140-
env: ${{ matrix.env }}
141126
run: |
142127
cd release
143128
./DDNet-Server shutdown
144129
145130
- name: Build headless client
146131
if: contains(matrix.os, 'ubuntu-latest')
147-
env: ${{ matrix.env }}
148132
run: |
149133
mkdir headless
150134
cd headless
151135
CFLAGS="$CFLAGS --coverage"
152136
CXXFLAGS="$CXXFLAGS --coverage"
153137
LDFLAGS="$LDFLAGS --coverage"
154138
${{ matrix.cmake-path }}cmake --version
155-
${{ matrix.cmake-path }}cmake ${{ matrix.cmake-args }} -DHEADLESS_CLIENT=ON -DCMAKE_BUILD_TYPE=Debug -Werror=dev -DDOWNLOAD_GTEST=ON -DDEV=ON -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG=. ..
139+
${{ matrix.cmake-path }}cmake -E env ${{ matrix.cmake-init-env }} ${{ matrix.cmake-path }}cmake ${{ matrix.cmake-args }} -DHEADLESS_CLIENT=ON -DCMAKE_BUILD_TYPE=Debug -Werror=dev -DDOWNLOAD_GTEST=ON -DDEV=ON -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG=. ..
156140
${{ matrix.cmake-path }}cmake --build . --config Debug ${{ matrix.build-args }}
157141
158142
- name: Test headless client (unit tests)
@@ -188,23 +172,21 @@ jobs:
188172

189173
- name: Build in release mode with debug info and all features on
190174
if: matrix.fancy
191-
env: ${{ matrix.env }}
192175
run: |
193176
mkdir fancy
194177
cd fancy
195-
${{ matrix.cmake-path }}cmake ${{ matrix.cmake-args }} -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDOWNLOAD_GTEST=ON -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. -DANTIBOT=ON -DWEBSOCKETS=ON ..
178+
${{ matrix.cmake-path }}cmake -E env ${{ matrix.cmake-init-env }} ${{ matrix.cmake-path }}cmake ${{ matrix.cmake-args }} -DCMAKE_BUILD_TYPE=RelWithDebInfo -DDOWNLOAD_GTEST=ON -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. -DANTIBOT=ON -DWEBSOCKETS=ON ..
196179
${{ matrix.cmake-path }}cmake --build . --config RelWithDebInfo --target everything ${{ matrix.build-args }}
197180
198181
- name: Test fancy
199182
if: matrix.fancy
200-
env: ${{ matrix.env }}
201183
run: |
184+
find /usr/lib/ -name '*libwebsockets*'
202185
cd fancy
203-
${{ matrix.cmake-path }}cmake --build . --config RelWithDebInfo --target run_tests ${{ matrix.build-args }}
186+
${{ matrix.cmake-path }}cmake -E env ${{ matrix.gtest-env }} ${{ matrix.cmake-path }}cmake --build . --config RelWithDebInfo --target run_tests ${{ matrix.build-args }}
204187
205188
- name: Run fancy server
206189
if: matrix.fancy
207-
env: ${{ matrix.env }}
208190
run: |
209191
cd fancy
210192
./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)