1c5b01ed15
This change vendors `wgpu` library in-tree and hooks up the initialization bits. It implements adapter and device initialization and adds a simple test. Complementary ecosystem tracker - https://github.com/gfx-rs/wgpu/issues/374 Current status: - [x] General - [x] figure out the IPC story - [ ] move wgpu crates into a dedicated folder (postponed as https://bugzilla.mozilla.org/show_bug.cgi?id=1594182) - [x] neko rebasing disaster - [x] Linux - [x] avoid depending on spirv_cross - [x] macOS - [x] due to cross-compiling shaders - [x] need the dependency update - [x] stop using gcc - [x] unexpected SSL header collision - https://phabricator.services.mozilla.com/D51148 - [x] undefined Metal symbols - [x] missing webrtc headers for IPDL magic - https://phabricator.services.mozilla.com/D51558 - [x] spirv-cross linking failure in ASAN - https://phabricator.services.mozilla.com/D52688 - [x] Windows - [x] due to "ipc-channel" not supporting Windows yet - [x] due to some exceptional stuff - [x] undefined symbol: `D3D12CreateDevice` - [x] d3d12.dll is not found, dxgi1_4 doesn't present - [x] d3d11.dll and dxgi.dll need to be explicitly loaded on win32 mingw - [x] libbacktrace fails to link on win32 mingw - [x] cc mislinking C++ standard library - [x] Android - [x] spirv-cross fails to build due to exceptions Update-1: We decided to go with IPDL mechanism instead of Rust based ipc-channel (or any alternatives), which unblocks Windows build. Update-2: It appears that WebGPUThreading isn't needed any more as the child thread (and its event loop) is now managed by IPDL infrastructure. This PR removes it 🎉 . Update-3: InstanceProvider is also removed. Update-4: All set, the try is green, waiting for dependent changes to go in. Differential Revision: https://phabricator.services.mozilla.com/D49458 --HG-- rename : dom/webgpu/Adapter.cpp => dom/webgpu/ipc/WebGPUTypes.h rename : third_party/rust/blake2b_simd/Cargo.toml => third_party/rust/ash/Cargo.toml rename : third_party/rust/uluru/Cargo.toml => third_party/rust/atom/Cargo.toml rename : third_party/rust/core-graphics/Cargo.toml => third_party/rust/cocoa/Cargo.toml rename : third_party/rust/crossbeam-deque/LICENSE-MIT => third_party/rust/cocoa/LICENSE-MIT rename : third_party/rust/core-graphics/src/lib.rs => third_party/rust/cocoa/src/lib.rs rename : third_party/rust/uluru/Cargo.toml => third_party/rust/colorful/Cargo.toml rename : third_party/rust/uluru/Cargo.toml => third_party/rust/copyless/Cargo.toml rename : third_party/rust/crossbeam-utils/.cargo-checksum.json => third_party/rust/crossbeam-utils-0.6.5/.cargo-checksum.json rename : third_party/rust/crossbeam-utils/CHANGELOG.md => third_party/rust/crossbeam-utils-0.6.5/CHANGELOG.md rename : third_party/rust/crossbeam-utils/Cargo.toml => third_party/rust/crossbeam-utils-0.6.5/Cargo.toml rename : third_party/rust/crossbeam-deque/LICENSE-MIT => third_party/rust/crossbeam-utils-0.6.5/LICENSE-MIT rename : third_party/rust/crossbeam-utils/README.md => third_party/rust/crossbeam-utils-0.6.5/README.md rename : third_party/rust/crossbeam-utils/benches/atomic_cell.rs => third_party/rust/crossbeam-utils-0.6.5/benches/atomic_cell.rs rename : third_party/rust/crossbeam-utils/src/atomic/atomic_cell.rs => third_party/rust/crossbeam-utils-0.6.5/src/atomic/atomic_cell.rs rename : third_party/rust/crossbeam-utils/src/atomic/mod.rs => third_party/rust/crossbeam-utils-0.6.5/src/atomic/mod.rs rename : third_party/rust/crossbeam-utils/src/backoff.rs => third_party/rust/crossbeam-utils-0.6.5/src/backoff.rs rename : third_party/rust/crossbeam-utils/src/cache_padded.rs => third_party/rust/crossbeam-utils-0.6.5/src/cache_padded.rs rename : third_party/rust/crossbeam-utils/src/lib.rs => third_party/rust/crossbeam-utils-0.6.5/src/lib.rs rename : third_party/rust/crossbeam-utils/src/thread.rs => third_party/rust/crossbeam-utils-0.6.5/src/thread.rs rename : third_party/rust/crossbeam-utils/tests/atomic_cell.rs => third_party/rust/crossbeam-utils-0.6.5/tests/atomic_cell.rs rename : third_party/rust/crossbeam-utils/tests/parker.rs => third_party/rust/crossbeam-utils-0.6.5/tests/parker.rs rename : third_party/rust/crossbeam-utils/tests/sharded_lock.rs => third_party/rust/crossbeam-utils-0.6.5/tests/sharded_lock.rs rename : third_party/rust/crossbeam-utils/tests/thread.rs => third_party/rust/crossbeam-utils-0.6.5/tests/thread.rs rename : third_party/rust/blake2b_simd/Cargo.toml => third_party/rust/gfx-auxil/Cargo.toml rename : third_party/rust/blake2b_simd/Cargo.toml => third_party/rust/gfx-backend-empty/Cargo.toml rename : third_party/rust/blake2b_simd/Cargo.toml => third_party/rust/hibitset/Cargo.toml rename : third_party/rust/crossbeam-deque/LICENSE-MIT => third_party/rust/hibitset/LICENSE-MIT rename : third_party/rust/crossbeam-deque/LICENSE-MIT => third_party/rust/metal/LICENSE-MIT rename : third_party/rust/uluru/Cargo.toml => third_party/rust/range-alloc/Cargo.toml rename : third_party/rust/blake2b_simd/Cargo.toml => third_party/rust/raw-window-handle/Cargo.toml rename : third_party/rust/blake2b_simd/Cargo.toml => third_party/rust/relevant/Cargo.toml rename : third_party/rust/crossbeam-deque/LICENSE-MIT => third_party/rust/relevant/LICENSE-MIT rename : third_party/rust/blake2b_simd/Cargo.toml => third_party/rust/rendy-descriptor/Cargo.toml rename : third_party/rust/uluru/Cargo.toml => third_party/rust/shared_library/Cargo.toml rename : third_party/rust/crossbeam-deque/LICENSE-MIT => third_party/rust/shared_library/LICENSE-MIT rename : third_party/rust/blake2b_simd/Cargo.toml => third_party/rust/storage-map/Cargo.toml rename : third_party/rust/core-graphics/Cargo.toml => third_party/rust/x11/Cargo.toml extra : moz-landing-system : lando |
||
---|---|---|
.. | ||
src | ||
tests | ||
.cargo-checksum.json | ||
Cargo.lock | ||
Cargo.toml | ||
LICENSE-APACHE | ||
LICENSE-MIT | ||
README.md |
README.md
cc-rs
A library to compile C/C++/assembly into a Rust library/application.
A simple library meant to be used as a build dependency with Cargo packages in
order to build a set of C/C++ files into a static archive. This crate calls out
to the most relevant compiler for a platform, for example using cl
on MSVC.
Note: this crate was recently renamed from the
gcc
crate, so if you're looking for thegcc
crate you're in the right spot!
Using cc-rs
First, you'll want to both add a build script for your crate (build.rs
) and
also add this crate to your Cargo.toml
via:
[build-dependencies]
cc = "1.0"
Next up, you'll want to write a build script like so:
// build.rs
fn main() {
cc::Build::new()
.file("foo.c")
.file("bar.c")
.compile("foo");
}
And that's it! Running cargo build
should take care of the rest and your Rust
application will now have the C files foo.c
and bar.c
compiled into a file
named libfoo.a. You can call the functions in Rust by declaring functions in
your Rust code like so:
extern {
fn foo_function();
fn bar_function();
}
pub fn call() {
unsafe {
foo_function();
bar_function();
}
}
fn main() {
// ...
}
External configuration via environment variables
To control the programs and flags used for building, the builder can set a number of different environment variables.
CFLAGS
- a series of space separated flags passed to compilers. Note that individual flags cannot currently contain spaces, so doing something like: "-L=foo\ bar" is not possible.CC
- the actual C compiler used. Note that this is used as an exact executable name, so (for example) no extra flags can be passed inside this variable, and the builder must ensure that there aren't any trailing spaces. This compiler must understand the-c
flag. For certainTARGET
s, it also is assumed to know about other flags (most common is-fPIC
).AR
- thear
(archiver) executable to use to build the static library.CRATE_CC_NO_DEFAULTS
- the default compiler flags may cause conflicts in some cross compiling scenarios. Setting this variable will disable the generation of default compiler flags.
Each of these variables can also be supplied with certain prefixes and suffixes, in the following prioritized order:
<var>_<target>
- for example,CC_x86_64-unknown-linux-gnu
<var>_<target_with_underscores>
- for example,CC_x86_64_unknown_linux_gnu
<build-kind>_<var>
- for example,HOST_CC
orTARGET_CFLAGS
<var>
- a plainCC
,AR
as above.
If none of these variables exist, cc-rs uses built-in defaults
In addition to the above optional environment variables, cc-rs
has some
functions with hard requirements on some variables supplied by cargo's
build-script driver that it has the TARGET
, OUT_DIR
, OPT_LEVEL
,
and HOST
variables.
Optional features
Parallel
Currently cc-rs supports parallel compilation (think make -jN
) but this
feature is turned off by default. To enable cc-rs to compile C/C++ in parallel,
you can change your dependency to:
[build-dependencies]
cc = { version = "1.0", features = ["parallel"] }
By default cc-rs will limit parallelism to $NUM_JOBS
, or if not present it
will limit it to the number of cpus on the machine. If you are using cargo,
use -jN
option of build
, test
and run
commands as $NUM_JOBS
is supplied by cargo.
Compile-time Requirements
To work properly this crate needs access to a C compiler when the build script is being run. This crate does not ship a C compiler with it. The compiler required varies per platform, but there are three broad categories:
- Unix platforms require
cc
to be the C compiler. This can be found by installing cc/clang on Linux distributions and Xcode on OSX, for example. - Windows platforms targeting MSVC (e.g. your target triple ends in
-msvc
) requirecl.exe
to be available and inPATH
. This is typically found in standard Visual Studio installations and thePATH
can be set up by running the appropriate developer tools shell. - Windows platforms targeting MinGW (e.g. your target triple ends in
-gnu
) requirecc
to be available inPATH
. We recommend the MinGW-w64 distribution, which is using the Win-builds installation system. You may also acquire it via MSYS2, as explained here. Make sure to install the appropriate architecture corresponding to your installation of rustc. GCC from older MinGW project is compatible only with 32-bit rust compiler.
C++ support
cc-rs
supports C++ libraries compilation by using the cpp
method on
Build
:
fn main() {
cc::Build::new()
.cpp(true) // Switch to C++ library compilation.
.file("foo.cpp")
.compile("libfoo.a");
}
When using C++ library compilation switch, the CXX
and CXXFLAGS
env
variables are used instead of CC
and CFLAGS
and the C++ standard library is
linked to the crate target.
CUDA C++ support
cc-rs
also supports compiling CUDA C++ libraries by using the cuda
method
on Build
(currently for GNU/Clang toolchains only):
fn main() {
cc::Build::new()
// Switch to CUDA C++ library compilation using NVCC.
.cuda(true)
// Generate code for Maxwell (GTX 970, 980, 980 Ti, Titan X).
.flag("-gencode").flag("arch=compute_52,code=sm_52")
// Generate code for Maxwell (Jetson TX1).
.flag("-gencode").flag("arch=compute_53,code=sm_53")
// Generate code for Pascal (GTX 1070, 1080, 1080 Ti, Titan Xp).
.flag("-gencode").flag("arch=compute_61,code=sm_61")
// Generate code for Pascal (Tesla P100).
.flag("-gencode").flag("arch=compute_60,code=sm_60")
// Generate code for Pascal (Jetson TX2).
.flag("-gencode").flag("arch=compute_62,code=sm_62")
.file("bar.cu")
.compile("libbar.a");
}
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in cc-rs by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.