Skip to content

Commit

Permalink
Fixed builds on MSVC and added Fmod support.
Browse files Browse the repository at this point in the history
Signed-off-by: Julia DeMille <me@jdemille.com>
  • Loading branch information
judemille committed Nov 25, 2023
1 parent e55bd74 commit c72eab2
Show file tree
Hide file tree
Showing 21 changed files with 47 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ XPLM301 = ["XPLM300"]
XPLM300 = ["XPLM210"]
XPLM210 = ["XPLM200"]
XPLM200 = []
fmod = []
mockall = ["dep:mockall"]

[package.metadata.docs.rs]
features = ["XPLM400"]
Expand Down
Empty file modified XPlaneSDK/CHeaders/Widgets/XPStandardWidgets.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/Widgets/XPUIGraphics.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/Widgets/XPWidgetDefs.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/Widgets/XPWidgetUtils.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/Widgets/XPWidgets.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/XPLM/XPLMCamera.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/XPLM/XPLMDataAccess.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/XPLM/XPLMDefs.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/XPLM/XPLMDisplay.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/XPLM/XPLMGraphics.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/XPLM/XPLMMenus.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/XPLM/XPLMNavigation.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/XPLM/XPLMPlanes.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/XPLM/XPLMPlugin.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/XPLM/XPLMProcessing.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/CHeaders/XPLM/XPLMUtilities.h
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/Libraries/Mac/XPLM.framework/XPLM
100755 → 100644
Empty file.
Empty file modified XPlaneSDK/Libraries/Mac/XPWidgets.framework/XPWidgets
100755 → 100644
Empty file.
56 changes: 33 additions & 23 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ fn get_clang_args(crate_path: &Path) -> Vec<String> {
r.push("-DXPLM200".to_string());
}

if cfg!(feature = "fmod") {
r.push("-D_FMOD_STUB_".to_string());
}

let cheaders = crate_path.join("XPlaneSDK/CHeaders");
let xplmheaders = cheaders.join("XPLM");
let widgetheaders = cheaders.join("Widgets");
Expand All @@ -46,12 +50,14 @@ fn handle_platform(crate_path: &Path) {
let triple = Triple::from_str(&target).unwrap();
match triple.operating_system {
OperatingSystem::Windows => {
assert!(
triple.architecture == Architecture::X86_64,
assert_eq!(
triple.architecture,
Architecture::X86_64,
"Unsupported target architecture! xplane-sys on Windows only supports x86_64."
);
assert!(
triple.environment == Environment::Msvc,
assert_eq!(
triple.environment,
Environment::Msvc,
"Unsupported environment! X-Plane uses the MSVC ABI. Compile for that target."
);
let library_path = crate_path.join("SDK/Libraries/Win");
Expand All @@ -61,7 +67,7 @@ fn handle_platform(crate_path: &Path) {
}
OperatingSystem::MacOSX { .. } => {
match triple.architecture {
Architecture::Aarch64(_) | Architecture::X86_64 => {},
Architecture::Aarch64(_) | Architecture::X86_64 => {}
_ => panic!("Unsupported target architecture! xplane-sys on Mac only supports x86_64 or aarch64.")
};
let library_path = crate_path.join("SDK/Libraries/Mac");
Expand All @@ -73,11 +79,12 @@ fn handle_platform(crate_path: &Path) {
println!("cargo:rustc-link-lib=framework=XPWidgets");
}
OperatingSystem::Linux => {
assert!(
triple.architecture == Architecture::X86_64,
assert_eq!(
triple.architecture,
Architecture::X86_64,
"Unsupported target architecture! xplane-sys on Linux only supports x86_64."
);
assert!(triple.environment == Environment::Gnu, "Unsupported environment! X-Plane runs on the GNU ABI on Linux, and so xplane-sys requires a GNU target.");
assert_eq!(triple.environment, Environment::Gnu, "Unsupported environment! X-Plane runs on the GNU ABI on Linux, and so xplane-sys requires a GNU target.");
} // No need to link libraries on Linux.
_ => panic!(
"Unsupported operating system! The X-Plane SDK only supports Windows, Mac, and Linux."
Expand All @@ -87,6 +94,7 @@ fn handle_platform(crate_path: &Path) {

#[derive(Debug)]
struct NamingHandler;

impl ParseCallbacks for NamingHandler {
fn int_macro(&self, name: &str, _value: i64) -> Option<IntKind> {
if name.starts_with("XPLM_VK") || name.starts_with("XPLM_KEY") {
Expand Down Expand Up @@ -206,27 +214,29 @@ fn main() {

let bindings_fns_only = bindings_builder
.with_codegen_config(bindgen::CodegenConfig::FUNCTIONS)
.blocklist_function("__va_start") // This symbol breaks builds on Windows, and is unneeded.
.blocklist_function("__report_gsfailure") // Likewise.
.generate()
.expect("Unable to generate bindings!")
.to_string();

let bindings = &[
r#"
#[cfg(feature = "mockall")]
use mockall::automock;
#[cfg_attr(feature = "mockall", automock)]
#[cfg_attr(feature = "mockall", allow(dead_code))] // Don't warn on not using mocked functions.
mod functions {
use super::*;
"#,
r#"#[cfg(feature = "mockall")]
use mockall::automock;
#[cfg_attr(feature = "mockall", automock)]
#[cfg_attr(feature = "mockall", allow(dead_code))] // Don't warn on not using mocked functions.
mod functions {
use super::*;
"#,
&bindings_fns_only,
r#"
}
#[cfg(not(feature = "mockall"))]
pub use functions::*;
#[cfg(feature = "mockall")]
pub use mock_functions::*;
"#,
r#"}
#[cfg(not(feature = "mockall"))]
#[doc(inline)]
pub use functions::*;
#[cfg(feature = "mockall")]
#[doc(inline)]
pub use mock_functions::*;
"#,
&bindings_except_fns,
]
.join("");
Expand Down
12 changes: 12 additions & 0 deletions src/combined.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
/*
* This file includes all the XPLM and XPWidgets headers
*/

#ifdef _FMOD_STUB_
#define _FMOD_COMMON_H
// Basic definitions to make bindings possible.
typedef void FMOD_STUDIO_SYSTEM;
typedef void FMOD_CHANNELGROUP;
typedef int FMOD_RESULT;
typedef int FMOD_SOUND_FORMAT;
typedef void FMOD_CHANNEL;
typedef void FMOD_VECTOR;
#endif

#include <XPStandardWidgets.h>
#include <XPUIGraphics.h>
#include <XPWidgetDefs.h>
Expand Down

0 comments on commit c72eab2

Please sign in to comment.