Skip to content

Commit

Permalink
Simplify rust workflow and clippy calls; address many warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Sep 26, 2022
1 parent c4978d8 commit 43b8776
Show file tree
Hide file tree
Showing 24 changed files with 104 additions and 143 deletions.
48 changes: 16 additions & 32 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,38 @@ env:
CARGO_TERM_COLOR: always

jobs:
build_windows:
check-windows:
runs-on: windows-2019
env:
LIBCLANG_PATH: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\Llvm\x64\bin'
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: clippy
- uses: Swatinem/rust-cache@v1

- uses: crazy-max/ghaction-chocolatey@v1
with:
args: install vulkan-sdk

- name: Build crates
uses: actions-rs/cargo@v1
- uses: ErichDonGubler/clippy-check@fix-windows-lf-breaking-reports
with:
command: build
args: -p alvr_xtask -p alvr_server -p alvr_launcher -p alvr_client_core --verbose
token: ${{ secrets.GITHUB_TOKEN }}

build_linux:
check-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: clippy
- uses: Swatinem/rust-cache@v1

- name: Build and install dependencies
Expand All @@ -50,22 +52,23 @@ jobs:
sudo apt install build-essential pkg-config nasm libva-dev libdrm-dev libvulkan-dev libx264-dev libx265-dev cmake libasound2-dev libjack-jackd2-dev libxrandr-dev libunwind-dev
cargo xtask prepare-deps --platform linux --no-nvidia
- name: Build crates
uses: actions-rs/cargo@v1
- uses: actions-rs/clippy-check@v1
with:
command: build
args: -p alvr_xtask -p alvr_launcher -p alvr_server --features gpl -p alvr_vulkan_layer -p alvr_vrcompositor_wrapper -p alvr_client_core --verbose
token: ${{ secrets.GITHUB_TOKEN }}
args: --features gpl

build_android:
build-android:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: aarch64-linux-android
override: true
Expand Down Expand Up @@ -102,7 +105,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: -p alvr_session --verbose
args: -p alvr_session

rustfmt:
runs-on: ubuntu-latest
Expand All @@ -117,23 +120,4 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
runs-on: windows-2019
env:
LIBCLANG_PATH: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\Llvm\x64\bin'
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: clippy
- uses: Swatinem/rust-cache@v1

- uses: ErichDonGubler/clippy-check@fix-windows-lf-breaking-reports
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: -p alvr_xtask -p alvr_common -p alvr_server -p alvr_launcher -p alvr_client_core
args: --all -- --check
4 changes: 2 additions & 2 deletions alvr/client_core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ fn main() {
.header("cpp/bindings.h")
.derive_default(true)
.generate()
.expect("bindings")
.unwrap()
.write_to_file(out_dir.join("bindings.rs"))
.expect("bindings.rs");
.unwrap();

for path in cpp_paths {
println!("cargo:rerun-if-changed={}", path.to_string_lossy());
Expand Down
7 changes: 6 additions & 1 deletion alvr/client_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![allow(non_upper_case_globals, non_snake_case, clippy::missing_safety_doc)]
#![allow(
non_upper_case_globals,
non_snake_case,
clippy::missing_safety_doc,
clippy::unseparated_literal_suffix
)]

mod connection;
mod connection_utils;
Expand Down
4 changes: 2 additions & 2 deletions alvr/launcher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl eframe::App for ALVRLauncher {
ui.add_space(15.0);
if !resetting {
if ui.button(text("Reset drivers and retry")).clicked() {
reset_and_retry(self.state.clone());
reset_and_retry(Arc::clone(&self.state));
}
} else {
ui.label(text("Please wait for multiple restarts"));
Expand Down Expand Up @@ -161,7 +161,7 @@ fn make_window() -> StrResult {
}));

thread::spawn({
let state = state.clone();
let state = Arc::clone(&state);
move || launcher_lifecycle(state)
});

Expand Down
4 changes: 2 additions & 2 deletions alvr/server/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ fn main() {
.header("cpp/alvr_server/bindings.h")
.derive_default(true)
.generate()
.expect("bindings")
.unwrap()
.write_to_file(out_dir.join("bindings.rs"))
.expect("bindings.rs");
.unwrap();

println!(
"cargo:rustc-link-search=native={}",
Expand Down
32 changes: 14 additions & 18 deletions alvr/server/cpp/alvr_server/OvrController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ vr::EVRInitError OvrController::Activate(vr::TrackedDeviceIndex_t unObjectId) {
const auto &settings = Settings::Instance();
if (isViveTracker) {
static constexpr const std::string_view vive_prefix = "vive_tracker_";
const auto &ctrlType = this->device_id == LEFT_HAND_ID
? settings.m_controllerTypeLeft
: settings.m_controllerTypeRight;
const auto &ctrlType = this->device_id == LEFT_HAND_ID ? settings.m_controllerTypeLeft
: settings.m_controllerTypeRight;
std::string ret = settings.mControllerRegisteredDeviceType;
if (ret.length() > 0 && ret[ret.length() - 1] != '/')
ret += '/';
Expand All @@ -121,13 +120,12 @@ vr::EVRInitError OvrController::Activate(vr::TrackedDeviceIndex_t unObjectId) {
vr::VRProperties()->SetInt32Property(
this->prop_container, vr::Prop_Axis0Type_Int32, vr::k_eControllerAxis_Joystick);

vr::VRProperties()->SetInt32Property(this->prop_container,
vr::Prop_ControllerRoleHint_Int32,
isViveTracker
? vr::TrackedControllerRole_Invalid
: (this->device_id == LEFT_HAND_ID
? vr::TrackedControllerRole_LeftHand
: vr::TrackedControllerRole_RightHand));
vr::VRProperties()->SetInt32Property(
this->prop_container,
vr::Prop_ControllerRoleHint_Int32,
isViveTracker ? vr::TrackedControllerRole_Invalid
: (this->device_id == LEFT_HAND_ID ? vr::TrackedControllerRole_LeftHand
: vr::TrackedControllerRole_RightHand));

vr::VRProperties()->SetStringProperty(this->prop_container,
vr::Prop_ControllerType_String,
Expand Down Expand Up @@ -419,7 +417,7 @@ vr::EVRInitError OvrController::Activate(vr::TrackedDeviceIndex_t unObjectId) {
vr::VRProperties()->SetInt32Property(
this->prop_container, vr::Prop_ControllerHandSelectionPriority_Int32, -1);
vr::HmdMatrix34_t l_transform = {
-1.f, 0.f, 0.f, 0.f, 0.f, 0.f, -1.f, 0.f, 0.f, -1.f, 0.f, 0.f};
{{-1.f, 0.f, 0.f, 0.f}, {0.f, 0.f, -1.f, 0.f}, {0.f, -1.f, 0.f, 0.f}}};
vr::VRProperties()->SetProperty(this->prop_container,
vr::Prop_StatusDisplayTransform_Matrix34,
&l_transform,
Expand Down Expand Up @@ -713,24 +711,22 @@ bool OvrController::onPoseUpdate(float predictionS,

if (this->device_id == LEFT_HAND_ID) {
double bonePosFixer[3] = {0.0, 0.05, -0.05};
vr::HmdVector3d_t posFix =
vrmath::quaternionRotateVector(pose.qRotation, bonePosFixer);
vr::HmdVector3d_t posFix = vrmath::quaternionRotateVector(pose.qRotation, bonePosFixer);
pose.vecPosition[0] = motion.position[0] + posFix.v[0];
pose.vecPosition[1] = motion.position[1] + posFix.v[1];
pose.vecPosition[2] = motion.position[2] + posFix.v[2];
} else {
double bonePosFixer[3] = {0.0, 0.05, -0.05};
vr::HmdVector3d_t posFix =
vrmath::quaternionRotateVector(pose.qRotation, bonePosFixer);
vr::HmdVector3d_t posFix = vrmath::quaternionRotateVector(pose.qRotation, bonePosFixer);
pose.vecPosition[0] = motion.position[0] + posFix.v[0];
pose.vecPosition[1] = motion.position[1] + posFix.v[1];
pose.vecPosition[2] = motion.position[2] + posFix.v[2];
}
} else {
pose.qRotation = HmdQuaternion_Init(motion.orientation.w,
motion.orientation.x,
motion.orientation.y,
motion.orientation.z); // controllerRotation;
motion.orientation.x,
motion.orientation.y,
motion.orientation.z); // controllerRotation;

pose.vecPosition[0] = motion.position[0];
pose.vecPosition[1] = motion.position[1];
Expand Down
2 changes: 1 addition & 1 deletion alvr/server/cpp/alvr_server/OvrHMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class OvrHmd : public TrackedDevice,
virtual void Deactivate();
virtual void EnterStandby() {}
void *GetComponent(const char *pchComponentNameAndVersion);
virtual void DebugRequest(const char *request, char *response_buffer, uint32_t size) {}
virtual void DebugRequest(const char *, char *, uint32_t) {}
virtual vr::DriverPose_t GetPose();

void OnPoseUpdated(uint64_t targetTimestampNs, float predictionS, AlvrDeviceMotion motion);
Expand Down
2 changes: 1 addition & 1 deletion alvr/server/cpp/alvr_server/OvrViveTrackerProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ vr::EVRInitError OvrViveTrackerProxy::Activate( vr::TrackedDeviceIndex_t unObjec
vr::VRProperties()->SetBoolProperty(propertyContainer, vr::Prop_DeviceIsCharging_Bool, false);
vr::VRProperties()->SetFloatProperty(propertyContainer, vr::Prop_DeviceBatteryPercentage_Float, 1.f); // Always charged

vr::HmdMatrix34_t l_transform = { -1.f, 0.f, 0.f, 0.f, 0.f, 0.f, -1.f, 0.f, 0.f, -1.f, 0.f, 0.f };
vr::HmdMatrix34_t l_transform = {{{-1.f, 0.f, 0.f, 0.f}, {0.f, 0.f, -1.f, 0.f}, {0.f, -1.f, 0.f, 0.f}}};
vr::VRProperties()->SetProperty(propertyContainer, vr::Prop_StatusDisplayTransform_Matrix34, &l_transform, sizeof(vr::HmdMatrix34_t), vr::k_unHmdMatrix34PropertyTag);

vr::VRProperties()->SetBoolProperty(propertyContainer, vr::Prop_Firmware_UpdateAvailable_Bool, false);
Expand Down
2 changes: 1 addition & 1 deletion alvr/server/cpp/alvr_server/Statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Statistics {
m_bitsSentInSecond += bytes * 8;
}

void EncodeOutput(uint64_t latencyUs) {
void EncodeOutput() {
CheckAndResetSecond();

m_framesInSecond++;
Expand Down
2 changes: 1 addition & 1 deletion alvr/server/cpp/platform/linux/CEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void CEncoder::Run() {

auto encode_end = std::chrono::steady_clock::now();

m_listener->GetStatistics()->EncodeOutput(std::chrono::duration_cast<std::chrono::microseconds>(encode_end - encode_start).count());
m_listener->GetStatistics()->EncodeOutput();

}
}
Expand Down
2 changes: 1 addition & 1 deletion alvr/server/cpp/platform/win32/VideoEncoderNVENC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void VideoEncoderNVENC::Transmit(ID3D11Texture2D *pTexture, uint64_t presentatio
m_NvNecoder->EncodeFrame(vPacket, &picParams);

if (m_Listener) {
m_Listener->GetStatistics()->EncodeOutput(GetTimestampUs() - presentationTime);
m_Listener->GetStatistics()->EncodeOutput();
}

m_nFrame += (int)vPacket.size();
Expand Down
2 changes: 1 addition & 1 deletion alvr/server/cpp/platform/win32/VideoEncoderSW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void VideoEncoderSW::Transmit(ID3D11Texture2D *pTexture, uint64_t presentationTi
}

// Send statistics to client
m_Listener->GetStatistics()->EncodeOutput(GetTimestampUs() - presentationTime);
m_Listener->GetStatistics()->EncodeOutput();

// Unmap the copied texture and delete it
m_d3dRender->GetContext()->Unmap(stagingTex.Get(), 0);
Expand Down
2 changes: 1 addition & 1 deletion alvr/server/cpp/platform/win32/VideoEncoderVCE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ void VideoEncoderVCE::Receive(amf::AMFData *data)
amf::AMFBufferPtr buffer(data); // query for buffer interface

if (m_Listener) {
m_Listener->GetStatistics()->EncodeOutput((current_time - start_time) / MICROSEC_TIME);
m_Listener->GetStatistics()->EncodeOutput();
}

char *p = reinterpret_cast<char *>(buffer->GetNative());
Expand Down
48 changes: 20 additions & 28 deletions alvr/server/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,42 +55,36 @@ fn mbits_to_bytes(value: u64) -> u32 {

#[derive(Clone)]
struct ClientId {
hostname: String,
ip: IpAddr,
}

async fn client_discovery(auto_trust_clients: bool) -> StrResult<ClientId> {
let (ip, handshake_packet) =
connection_utils::search_client_loop(|handshake_packet| async move {
let mut data_manager_ref = SERVER_DATA_MANAGER.write();
data_manager_ref.update_client_list(
handshake_packet.hostname.clone(),
ClientListAction::AddIfMissing {
display_name: handshake_packet.device_name,
},
Some(&CLIENTS_UPDATED_NOTIFIER),
);

if let Some(connection_desc) = data_manager_ref
.client_list()
.get(&handshake_packet.hostname)
{
connection_desc.trusted || auto_trust_clients
} else {
false
}
})
.await?;
let (ip, _) = connection_utils::search_client_loop(|handshake_packet| async move {
let mut data_manager_ref = SERVER_DATA_MANAGER.write();
data_manager_ref.update_client_list(
handshake_packet.hostname.clone(),
ClientListAction::AddIfMissing {
display_name: handshake_packet.device_name,
},
Some(&CLIENTS_UPDATED_NOTIFIER),
);

Ok(ClientId {
hostname: handshake_packet.hostname,
ip,
if let Some(connection_desc) = data_manager_ref
.client_list()
.get(&handshake_packet.hostname)
{
connection_desc.trusted || auto_trust_clients
} else {
false
}
})
.await?;

Ok(ClientId { ip })
}

struct ConnectionInfo {
client_ip: IpAddr,
version: Option<Version>,
control_sender: ControlSocketSender<ServerControlPacket>,
control_receiver: ControlSocketReceiver<ClientControlPacket>,
microphone_sample_rate: u32,
Expand Down Expand Up @@ -456,7 +450,6 @@ async fn client_handshake(

Ok(ConnectionInfo {
client_ip,
version,
control_sender,
control_receiver,
microphone_sample_rate: headset_info.microphone_sample_rate,
Expand Down Expand Up @@ -548,7 +541,6 @@ async fn connection_pipeline() -> StrResult {

let ConnectionInfo {
client_ip,
version: _,
control_sender,
mut control_receiver,
microphone_sample_rate,
Expand Down
2 changes: 1 addition & 1 deletion alvr/server/src/connection_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub async fn search_client_loop<F: Future<Output = bool>>(
.await
.map_err(err!())?;

let mut packet_buffer = [0u8; MAX_HANDSHAKE_PACKET_SIZE_BYTES];
let mut packet_buffer = [0_u8; MAX_HANDSHAKE_PACKET_SIZE_BYTES];

loop {
let (handshake_packet_size, client_address) =
Expand Down
3 changes: 2 additions & 1 deletion alvr/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ mod web_server;
non_camel_case_types,
non_upper_case_globals,
dead_code,
non_snake_case
non_snake_case,
clippy::unseparated_literal_suffix
)]
mod bindings {
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
Expand Down
Loading

0 comments on commit 43b8776

Please sign in to comment.