Skip to content

Commit 9dab8c0

Browse files
authored
Merge pull request #1 from Traverse-Research/steamworks-refactors
This PR includes the following changes: Update steamworks SDK to 1.61 Update Rust dependencies Minor updates to CI Moved to runtime library loading through libloading Only ported over APIs that we require for our internal projects Simplified steamworks-sys's build.rs Copy steam sdk library to target_dir instead of out_dir When reviewing, focus on the following files: steamworks/lib.rs steamworks-sys/build.rs
2 parents 5fc8ef1 + 1f6e2d3 commit 9dab8c0

Some content is hidden

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

43 files changed

+71065
-75570
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ jobs:
1010
strategy:
1111
matrix:
1212
os: [windows-latest, ubuntu-latest, macos-latest]
13-
toolchain: [stable, nightly, "1.73.0"]
1413
runs-on: ${{ matrix.os }}
1514
steps:
1615
- uses: actions/checkout@v2
1716

1817
- uses: actions-rs/toolchain@v1
1918
id: toolchain
2019
with:
21-
toolchain: ${{ matrix.toolchain }}
20+
toolchain: stable
2221
profile: minimal
2322
components: rustfmt, clippy
2423
override: true
@@ -27,15 +26,6 @@ jobs:
2726
run: sudo apt-get update; sudo apt-get install --no-install-recommends libudev-dev libx11-dev libxi-dev libgl1-mesa-dev libasound2-dev libxcb-shape0-dev libxcb-xfixes0-dev
2827
if: runner.os == 'linux'
2928

30-
- name: Setup cache
31-
uses: actions/cache@v2
32-
with:
33-
path: |
34-
~/.cargo/registry
35-
~/.cargo/git
36-
target
37-
key: ${{ runner.os }}-test-rustc-${{ steps.toolchain.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.lock') }}
38-
3929
- uses: actions-rs/cargo@v1
4030
if: runner.os == 'linux'
4131
with:
@@ -44,7 +34,7 @@ jobs:
4434

4535
- uses: actions-rs/cargo@v1
4636
with:
47-
command: build
37+
command: check
4838
args: --all
4939
env:
5040
CARGO_INCREMENTAL: 0
Lines changed: 53 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,53 @@
1-
name: Rebuild bindings
2-
3-
on: workflow_dispatch
4-
5-
env:
6-
CARGO_TERM_COLOR: always
7-
8-
jobs:
9-
build:
10-
strategy:
11-
matrix:
12-
os: [windows-latest, ubuntu-latest, macos-latest]
13-
runs-on: ${{ matrix.os }}
14-
15-
steps:
16-
- uses: actions/checkout@v2
17-
18-
- uses: actions-rs/toolchain@v1
19-
id: toolchain
20-
with:
21-
toolchain: stable
22-
profile: minimal
23-
components: rustfmt, clippy
24-
override: true
25-
26-
- name: Install alsa and udev
27-
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
28-
if: runner.os == 'linux'
29-
30-
- name: Setup cache
31-
uses: actions/cache@v2
32-
with:
33-
path: |
34-
~/.cargo/registry
35-
~/.cargo/git
36-
target
37-
key: ${{ runner.os }}-test-rustc-${{ steps.toolchain.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.lock') }}
38-
39-
- run: cargo build --features "rebuild-bindings"
40-
working-directory: steamworks-sys
41-
env:
42-
STEAM_SDK_LOCATION: ./lib/steam
43-
44-
- uses: actions/upload-artifact@v4
45-
with:
46-
name: artifact-linux-bindings
47-
path: steamworks-sys/src/linux_bindings.rs
48-
if: matrix.os == 'ubuntu-latest'
49-
50-
- uses: actions/upload-artifact@v4
51-
with:
52-
name: artifact-macos-bindings
53-
path: steamworks-sys/src/macos_bindings.rs
54-
if: matrix.os == 'macos-latest'
55-
56-
- uses: actions/upload-artifact@v4
57-
with:
58-
name: artifact-windows-bindings
59-
path: steamworks-sys/src/windows_bindings.rs
60-
if: matrix.os == 'windows-latest'
1+
name: Rebuild bindings
2+
3+
on: workflow_dispatch
4+
5+
env:
6+
CARGO_TERM_COLOR: always
7+
8+
jobs:
9+
build:
10+
strategy:
11+
matrix:
12+
include:
13+
- os: windows-latest
14+
target: x86_64-pc-windows-gnu
15+
- os: ubuntu-latest
16+
target: x86_64-unknown-linux-gnu
17+
- os: macos-latest
18+
target: x86_64-apple-darwin
19+
runs-on: ${{ matrix.os }}
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
- uses: actions-rs/toolchain@v1
24+
with:
25+
toolchain: stable
26+
target: ${{ matrix.target }}
27+
profile: minimal
28+
components: rustfmt, clippy
29+
30+
- name: Install alsa and udev
31+
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
32+
if: runner.os == 'linux'
33+
34+
- run: cargo build --features "rebuild-bindings" --target ${{ matrix.target }}
35+
working-directory: steamworks-sys
36+
37+
- uses: actions/upload-artifact@v4
38+
with:
39+
name: artifact-linux-bindings
40+
path: steamworks-sys/src/linux_bindings.rs
41+
if: matrix.os == 'ubuntu-latest'
42+
43+
- uses: actions/upload-artifact@v4
44+
with:
45+
name: artifact-macos-bindings
46+
path: steamworks-sys/src/macos_bindings.rs
47+
if: matrix.os == 'macos-latest'
48+
49+
- uses: actions/upload-artifact@v4
50+
with:
51+
name: artifact-windows-bindings
52+
path: steamworks-sys/src/windows_bindings.rs
53+
if: matrix.os == 'windows-latest'

Cargo.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ image = ["dep:image"]
1919
[workspace]
2020
members = [
2121
"./steamworks-sys",
22-
"examples/chat-example",
23-
"examples/workshop",
24-
"examples/lobby", "examples/networking-messages",
22+
# "examples/chat-example",
23+
# "examples/workshop",
24+
# "examples/lobby",
25+
# "examples/networking-messages",
2526
]
2627

2728
[dependencies]
2829
steamworks-sys = { path = "./steamworks-sys", version = "0.11.0" }
29-
thiserror = "1.0"
30-
bitflags = "1.2"
30+
libloading = { version = "0.8", default-features = false }
31+
thiserror = "2.0"
32+
bitflags = "2.8"
3133
lazy_static = "1.4"
3234
serde = { version = "1.0", features = ["derive"], optional = true }
3335
paste = "1.0.11"
34-
image = { version = "0.25.1", optional = true, default-features = false }
36+
image = { version = "0.25", optional = true, default-features = false }
3537

3638
[dev-dependencies]
37-
serial_test = "1"
39+
serial_test = "3.2"

src/app.rs

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl From<u32> for AppId {
1313
/// Access to the steam apps interface
1414
pub struct Apps<Manager> {
1515
pub(crate) apps: *mut sys::ISteamApps,
16-
pub(crate) _inner: Arc<Inner<Manager>>,
16+
pub(crate) inner: Arc<Inner<Manager>>,
1717
}
1818

1919
impl<Manager> Apps<Manager> {
@@ -22,13 +22,21 @@ impl<Manager> Apps<Manager> {
2222
///
2323
/// This does not mean the user owns the game.
2424
pub fn is_app_installed(&self, app_id: AppId) -> bool {
25-
unsafe { sys::SteamAPI_ISteamApps_BIsAppInstalled(self.apps, app_id.0) }
25+
unsafe {
26+
self.inner
27+
.lib
28+
.SteamAPI_ISteamApps_BIsAppInstalled(self.apps, app_id.0)
29+
}
2630
}
2731

2832
/// Returns whether the user owns the specific dlc and has it
2933
/// installed.
3034
pub fn is_dlc_installed(&self, app_id: AppId) -> bool {
31-
unsafe { sys::SteamAPI_ISteamApps_BIsDlcInstalled(self.apps, app_id.0) }
35+
unsafe {
36+
self.inner
37+
.lib
38+
.SteamAPI_ISteamApps_BIsDlcInstalled(self.apps, app_id.0)
39+
}
3240
}
3341

3442
/// Returns whether the user is subscribed to the app with the given
@@ -37,39 +45,47 @@ impl<Manager> Apps<Manager> {
3745
/// This should only be used to check ownership of a game related to
3846
/// yours (e.g. demo).
3947
pub fn is_subscribed_app(&self, app_id: AppId) -> bool {
40-
unsafe { sys::SteamAPI_ISteamApps_BIsSubscribedApp(self.apps, app_id.0) }
48+
unsafe {
49+
self.inner
50+
.lib
51+
.SteamAPI_ISteamApps_BIsSubscribedApp(self.apps, app_id.0)
52+
}
4153
}
4254

4355
/// Returns whether the user is subscribed via a free weekend
4456
pub fn is_subscribed_from_free_weekend(&self) -> bool {
45-
unsafe { sys::SteamAPI_ISteamApps_BIsSubscribedFromFreeWeekend(self.apps) }
57+
unsafe {
58+
self.inner
59+
.lib
60+
.SteamAPI_ISteamApps_BIsSubscribedFromFreeWeekend(self.apps)
61+
}
4662
}
4763

4864
/// Returns whether the user has a VAC ban on their account.
4965
pub fn is_vac_banned(&self) -> bool {
50-
unsafe { sys::SteamAPI_ISteamApps_BIsVACBanned(self.apps) }
66+
unsafe { self.inner.lib.SteamAPI_ISteamApps_BIsVACBanned(self.apps) }
5167
}
5268

5369
/// Returns whether the license for the current app ID
5470
/// is for cyber cafes.
5571
pub fn is_cybercafe(&self) -> bool {
56-
unsafe { sys::SteamAPI_ISteamApps_BIsCybercafe(self.apps) }
72+
unsafe { self.inner.lib.SteamAPI_ISteamApps_BIsCybercafe(self.apps) }
5773
}
5874

5975
/// Returns whether the license for the current app ID
6076
/// provides low violence depots.
6177
pub fn is_low_violence(&self) -> bool {
62-
unsafe { sys::SteamAPI_ISteamApps_BIsLowViolence(self.apps) }
78+
unsafe { self.inner.lib.SteamAPI_ISteamApps_BIsLowViolence(self.apps) }
6379
}
6480

6581
/// Returns whether the user is subscribed to the current app ID
6682
pub fn is_subscribed(&self) -> bool {
67-
unsafe { sys::SteamAPI_ISteamApps_BIsSubscribed(self.apps) }
83+
unsafe { self.inner.lib.SteamAPI_ISteamApps_BIsSubscribed(self.apps) }
6884
}
6985

7086
/// Returns the build id of this app.
7187
pub fn app_build_id(&self) -> i32 {
72-
unsafe { sys::SteamAPI_ISteamApps_GetAppBuildId(self.apps) as i32 }
88+
unsafe { self.inner.lib.SteamAPI_ISteamApps_GetAppBuildId(self.apps) as i32 }
7389
}
7490

7591
/// Returns the installation folder of the app with the given ID.
@@ -79,7 +95,7 @@ impl<Manager> Apps<Manager> {
7995
pub fn app_install_dir(&self, app_id: AppId) -> String {
8096
unsafe {
8197
let mut buffer = vec![0; 2048];
82-
sys::SteamAPI_ISteamApps_GetAppInstallDir(
98+
self.inner.lib.SteamAPI_ISteamApps_GetAppInstallDir(
8399
self.apps,
84100
app_id.0,
85101
buffer.as_mut_ptr(),
@@ -94,13 +110,16 @@ impl<Manager> Apps<Manager> {
94110
///
95111
/// Differs from the current user if the app is borrowed.
96112
pub fn app_owner(&self) -> SteamId {
97-
unsafe { SteamId(sys::SteamAPI_ISteamApps_GetAppOwner(self.apps)) }
113+
unsafe { SteamId(self.inner.lib.SteamAPI_ISteamApps_GetAppOwner(self.apps)) }
98114
}
99115

100116
/// Returns a list of languages that the current app supports.
101117
pub fn available_game_languages(&self) -> Vec<String> {
102118
unsafe {
103-
let langs = sys::SteamAPI_ISteamApps_GetAvailableGameLanguages(self.apps);
119+
let langs = self
120+
.inner
121+
.lib
122+
.SteamAPI_ISteamApps_GetAvailableGameLanguages(self.apps);
104123
let langs = CStr::from_ptr(langs);
105124
let langs = langs.to_string_lossy();
106125
langs.split(',').map(|v| v.to_owned()).collect()
@@ -113,7 +132,10 @@ impl<Manager> Apps<Manager> {
113132
/// used for the steam UI.
114133
pub fn current_game_language(&self) -> String {
115134
unsafe {
116-
let lang = sys::SteamAPI_ISteamApps_GetCurrentGameLanguage(self.apps);
135+
let lang = self
136+
.inner
137+
.lib
138+
.SteamAPI_ISteamApps_GetCurrentGameLanguage(self.apps);
117139
let lang = CStr::from_ptr(lang);
118140
lang.to_string_lossy().into_owned()
119141
}
@@ -126,7 +148,7 @@ impl<Manager> Apps<Manager> {
126148
pub fn current_beta_name(&self) -> Option<String> {
127149
unsafe {
128150
let mut buffer = vec![0; 256];
129-
if sys::SteamAPI_ISteamApps_GetCurrentBetaName(
151+
if self.inner.lib.SteamAPI_ISteamApps_GetCurrentBetaName(
130152
self.apps,
131153
buffer.as_mut_ptr(),
132154
buffer.len() as _,
@@ -147,7 +169,7 @@ impl<Manager> Apps<Manager> {
147169
pub fn launch_command_line(&self) -> String {
148170
unsafe {
149171
let mut buffer = vec![0; 256];
150-
let _bytes = sys::SteamAPI_ISteamApps_GetLaunchCommandLine(
172+
let _bytes = self.inner.lib.SteamAPI_ISteamApps_GetLaunchCommandLine(
151173
self.apps,
152174
buffer.as_mut_ptr(),
153175
buffer.len() as _,

src/callback.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use super::*;
22

3-
use crate::sys;
4-
53
use std::sync::{Arc, Weak};
64

75
pub unsafe trait Callback {
@@ -58,6 +56,7 @@ where
5856
}
5957
}
6058

59+
#[allow(dead_code)]
6160
pub(crate) unsafe fn register_call_result<C, F, Manager>(
6261
inner: &Arc<Inner<Manager>>,
6362
api_call: sys::SteamAPICall_t,

0 commit comments

Comments
 (0)