rust/tests/ui/abi/foreign/foreign-call-no-runtime.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.3 KiB
Rust
Raw Normal View History

// run-pass
// ignore-emscripten no threads support
std: Depend directly on crates.io crates Ever since we added a Cargo-based build system for the compiler the standard library has always been a little special, it's never been able to depend on crates.io crates for runtime dependencies. This has been a result of various limitations, namely that Cargo doesn't understand that crates from crates.io depend on libcore, so Cargo tries to build crates before libcore is finished. I had an idea this afternoon, however, which lifts the strategy from #52919 to directly depend on crates.io crates from the standard library. After all is said and done this removes a whopping three submodules that we need to manage! The basic idea here is that for any crate `std` depends on it adds an *optional* dependency on an empty crate on crates.io, in this case named `rustc-std-workspace-core`. This crate is overridden via `[patch]` in this repository to point to a local crate we write, and *that* has a `path` dependency on libcore. Note that all `no_std` crates also depend on `compiler_builtins`, but if we're not using submodules we can publish `compiler_builtins` to crates.io and all crates can depend on it anyway! The basic strategy then looks like: * The standard library (or some transitive dep) decides to depend on a crate `foo`. * The standard library adds ```toml [dependencies] foo = { version = "0.1", features = ['rustc-dep-of-std'] } ``` * The crate `foo` has an optional dependency on `rustc-std-workspace-core` * The crate `foo` has an optional dependency on `compiler_builtins` * The crate `foo` has a feature `rustc-dep-of-std` which activates these crates and any other necessary infrastructure in the crate. A sample commit for `dlmalloc` [turns out to be quite simple][commit]. After that all `no_std` crates should largely build "as is" and still be publishable on crates.io! Notably they should be able to continue to use stable Rust if necessary, since the `rename-dependency` feature of Cargo is soon stabilizing. As a proof of concept, this commit removes the `dlmalloc`, `libcompiler_builtins`, and `libc` submodules from this repository. Long thorns in our side these are now gone for good and we can directly depend on crates.io! It's hoped that in the long term we can bring in other crates as necessary, but for now this is largely intended to simply make it easier to manage these crates and remove submodules. This should be a transparent non-breaking change for all users, but one possible stickler is that this almost for sure breaks out-of-tree `std`-building tools like `xargo` and `cargo-xbuild`. I think it should be relatively easy to get them working, however, as all that's needed is an entry in the `[patch]` section used to build the standard library. Hopefully we can work with these tools to solve this problem! [commit]: https://github.com/alexcrichton/dlmalloc-rs/commit/28ee12db813a3b650a7c25d1c36d2c17dcb88ae3
2018-11-19 23:52:50 -06:00
#![feature(rustc_private)]
2014-02-26 11:58:41 -06:00
extern crate libc;
core: Remove the cast module This commit revisits the `cast` module in libcore and libstd, and scrutinizes all functions inside of it. The result was to remove the `cast` module entirely, folding all functionality into the `mem` module. Specifically, this is the fate of each function in the `cast` module. * transmute - This function was moved to `mem`, but it is now marked as #[unstable]. This is due to planned changes to the `transmute` function and how it can be invoked (see the #[unstable] comment). For more information, see RFC 5 and #12898 * transmute_copy - This function was moved to `mem`, with clarification that is is not an error to invoke it with T/U that are different sizes, but rather that it is strongly discouraged. This function is now #[stable] * forget - This function was moved to `mem` and marked #[stable] * bump_box_refcount - This function was removed due to the deprecation of managed boxes as well as its questionable utility. * transmute_mut - This function was previously deprecated, and removed as part of this commit. * transmute_mut_unsafe - This function doesn't serve much of a purpose when it can be achieved with an `as` in safe code, so it was removed. * transmute_lifetime - This function was removed because it is likely a strong indication that code is incorrect in the first place. * transmute_mut_lifetime - This function was removed for the same reasons as `transmute_lifetime` * copy_lifetime - This function was moved to `mem`, but it is marked `#[unstable]` now due to the likelihood of being removed in the future if it is found to not be very useful. * copy_mut_lifetime - This function was also moved to `mem`, but had the same treatment as `copy_lifetime`. * copy_lifetime_vec - This function was removed because it is not used today, and its existence is not necessary with DST (copy_lifetime will suffice). In summary, the cast module was stripped down to these functions, and then the functions were moved to the `mem` module. transmute - #[unstable] transmute_copy - #[stable] forget - #[stable] copy_lifetime - #[unstable] copy_mut_lifetime - #[unstable] [breaking-change]
2014-05-09 12:34:51 -05:00
use std::mem;
2015-02-17 21:49:22 -06:00
use std::thread;
2016-11-23 18:09:51 -06:00
#[link(name = "rust_test_helpers", kind = "static")]
2020-09-01 16:12:52 -05:00
extern "C" {
fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t), data: libc::uintptr_t) -> libc::uintptr_t;
}
pub fn main() {
unsafe {
2020-09-01 16:12:52 -05:00
thread::spawn(move || {
let i: isize = 100;
rust_dbg_call(callback_isize, mem::transmute(&i));
2020-09-01 16:12:52 -05:00
})
.join()
.unwrap();
2020-09-01 16:12:52 -05:00
thread::spawn(move || {
let i: i32 = 100;
rust_dbg_call(callback_i32, mem::transmute(&i));
2020-09-01 16:12:52 -05:00
})
.join()
.unwrap();
2020-09-01 16:12:52 -05:00
thread::spawn(move || {
let i: i64 = 100;
rust_dbg_call(callback_i64, mem::transmute(&i));
2020-09-01 16:12:52 -05:00
})
.join()
.unwrap();
}
}
2020-09-01 16:12:52 -05:00
extern "C" fn callback_isize(data: libc::uintptr_t) {
unsafe {
let data: *const isize = mem::transmute(data);
2015-01-25 15:05:03 -06:00
assert_eq!(*data, 100);
}
}
2020-09-01 16:12:52 -05:00
extern "C" fn callback_i64(data: libc::uintptr_t) {
unsafe {
let data: *const i64 = mem::transmute(data);
assert_eq!(*data, 100);
}
}
2020-09-01 16:12:52 -05:00
extern "C" fn callback_i32(data: libc::uintptr_t) {
unsafe {
let data: *const i32 = mem::transmute(data);
assert_eq!(*data, 100);
}
}