Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: modify Rust crate to support Windows #41

Merged
merged 2 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,34 @@ jobs:
- uses: actions/checkout@v2
- run: rustup component add rustfmt
- run: cargo fmt --all -- --check

rust_build:
name: Check Rust crate
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
defaults:
run:
working-directory: ittapi-rs
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Build Rust crate
run: cargo build
# On Windows, libclang.dll can be found in two places, including a
# mingw directory. As we're not using any of mingw tool in our case, we can
# just remove it.
# See also: https://github.com/actions/virtual-environments/issues/2208
- name: Remove spurious mingw directory (on Windows)
shell: powershell
run: Remove-Item -LiteralPath "C:\msys64\" -Force -Recurse
if: matrix.os == 'windows-latest'
- name: Test Rust crate
run: cargo test
# For some strange reason, the process of building the upstream library will result in source
# file changes on Windows; once this is resolved, remove `--allow-dirty`.
- name: Check crate is publishable
run: cargo publish --dry-run --allow-dirty
1 change: 0 additions & 1 deletion ittapi-rs/CMakeLists.txt

This file was deleted.

3 changes: 0 additions & 3 deletions ittapi-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ keywords = ["vtune", "profiling", "code-generation"]

[dependencies]

[features]
force_32 = []

[build-dependencies]
cc = "1.0.72"

Expand Down
4 changes: 2 additions & 2 deletions ittapi-rs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ are available on its [README].
[README]: https://github.com/intel/ittapi#readme
[convention]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#-sys-packages

> IMPORTANT NOTE: this package is currently only tested on several Linux platforms (recent Ubuntu
> and Fedora builds) but support for other platforms is intended; contributions are welcome!
> IMPORTANT NOTE: this package is currently only tested on Linux, macOS, and Windows platforms but
> support for other platforms is intended; contributions are welcome!

If you are interested in using VTune to profile Rust applications, you may find the following guide
helpful: [Wasmtime Docs: Using VTune on
Expand Down
37 changes: 6 additions & 31 deletions ittapi-rs/build.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
//! Build the `ittapi` C library in the parent directory. The `cc` configuration here should match
//! that of the parent directories `CMakeLists.txt` (TODO: keep these in sync,
//! https://github.com/intel/ittapi/issues/36).
#![allow(unused)]
use std::env;
use std::path::PathBuf;

#[cfg(target_os = "windows")]
fn main() {}

#[cfg(not(target_os = "windows"))]
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let out_path = PathBuf::from(out_dir);

#[cfg(not(feature = "force_32"))]
{
cc::Build::new()
.file("src/ittnotify/ittnotify_static.c")
.file("src/ittnotify/jitprofiling.c")
.include("src/ittnotify/")
.include("include/")
.compile("ittnotify");
}

#[cfg(feature = "force_32")]
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
{
cc::Build::new()
.file("src/ittnotify/ittnotify_static.c")
.file("src/ittnotify/jitprofiling.c")
.define("FORCE_32", "ON")
.include("src/ittnotify/")
.include("include/")
.compile("ittnotify");
}
cc::Build::new()
.file("c-library/src/ittnotify/ittnotify_static.c")
.file("c-library/src/ittnotify/jitprofiling.c")
.include("c-library/src/ittnotify/")
.include("c-library/include/")
.compile("ittnotify");
}
1 change: 1 addition & 0 deletions ittapi-rs/c-library
1 change: 0 additions & 1 deletion ittapi-rs/include

This file was deleted.

1 change: 0 additions & 1 deletion ittapi-rs/src/ittnotify

This file was deleted.

21 changes: 19 additions & 2 deletions ittapi-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
#![allow(unused)]
include!("ittnotify_bindings.rs");
include!("jitprofiling_bindings.rs");

// The ITT bindings are OS-specific: they contain OS-specific constants (e.g. `ITT_OS` and
// `ITT_PLATFORM`) and some of the Windows structure sizes are different. Because of this, we
// generate bindings separately for each OS. TODO handle unsupported OSes gracefully here.
#[cfg(target_os = "linux")]
include!("linux/ittnotify_bindings.rs");
#[cfg(target_os = "macos")]
include!("macos/ittnotify_bindings.rs");
#[cfg(target_os = "windows")]
include!("windows/ittnotify_bindings.rs");

// The JIT profiling bindings are almost OS-agnostic, but slight differences with `c_uint` vs
// `c_int`, e.g., force us to use separate bindings.
#[cfg(target_os = "linux")]
include!("linux/jitprofiling_bindings.rs");
#[cfg(target_os = "macos")]
include!("macos/jitprofiling_bindings.rs");
#[cfg(target_os = "windows")]
include!("windows/jitprofiling_bindings.rs");
Loading