Skip to content

Commit d4187e6

Browse files
committed
Make mini_core_hello_world work on Windows once TLS is supported
1 parent 282e305 commit d4187e6

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

example/mini_core.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ pub trait FnMut<Args>: FnOnce<Args> {
403403
#[track_caller]
404404
pub fn panic(_msg: &str) -> ! {
405405
unsafe {
406-
libc::puts("Panicking\n\0" as *const str as *const u8);
406+
libc::puts("Panicking\n\0" as *const str as *const i8);
407407
intrinsics::abort();
408408
}
409409
}
@@ -502,9 +502,10 @@ pub mod intrinsics {
502502
}
503503

504504
pub mod libc {
505-
#[link(name = "c")]
505+
#[cfg_attr(not(windows), link(name = "c"))]
506+
#[cfg_attr(windows, link(name = "msvcrt"))]
506507
extern "C" {
507-
pub fn puts(s: *const u8) -> i32;
508+
pub fn puts(s: *const i8) -> i32;
508509
pub fn printf(format: *const i8, ...) -> i32;
509510
pub fn malloc(size: usize) -> *mut u8;
510511
pub fn free(ptr: *mut u8);

example/mini_core_hello_world.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern crate mini_core;
1212
use mini_core::*;
1313
use mini_core::libc::*;
1414

15-
unsafe extern "C" fn my_puts(s: *const u8) {
15+
unsafe extern "C" fn my_puts(s: *const i8) {
1616
puts(s);
1717
}
1818

@@ -37,7 +37,7 @@ trait SomeTrait {
3737
impl SomeTrait for &'static str {
3838
fn object_safe(&self) {
3939
unsafe {
40-
puts(*self as *const str as *const u8);
40+
puts(*self as *const str as *const i8);
4141
}
4242
}
4343
}
@@ -52,15 +52,15 @@ struct NoisyDropInner;
5252
impl Drop for NoisyDrop {
5353
fn drop(&mut self) {
5454
unsafe {
55-
puts(self.text as *const str as *const u8);
55+
puts(self.text as *const str as *const i8);
5656
}
5757
}
5858
}
5959

6060
impl Drop for NoisyDropInner {
6161
fn drop(&mut self) {
6262
unsafe {
63-
puts("Inner got dropped!\0" as *const str as *const u8);
63+
puts("Inner got dropped!\0" as *const str as *const i8);
6464
}
6565
}
6666
}
@@ -82,9 +82,9 @@ fn start<T: Termination + 'static>(
8282
argv: *const *const u8,
8383
) -> isize {
8484
if argc == 3 {
85-
unsafe { puts(*argv); }
86-
unsafe { puts(*((argv as usize + intrinsics::size_of::<*const u8>()) as *const *const u8)); }
87-
unsafe { puts(*((argv as usize + 2 * intrinsics::size_of::<*const u8>()) as *const *const u8)); }
85+
unsafe { puts(*argv as *const i8); }
86+
unsafe { puts(*((argv as usize + intrinsics::size_of::<*const u8>()) as *const *const i8)); }
87+
unsafe { puts(*((argv as usize + 2 * intrinsics::size_of::<*const u8>()) as *const *const i8)); }
8888
}
8989

9090
main().report();
@@ -154,11 +154,11 @@ fn main() {
154154
printf("Hello %s\n\0" as *const str as *const i8, "printf\0" as *const str as *const i8);
155155

156156
let hello: &[u8] = b"Hello\0" as &[u8; 6];
157-
let ptr: *const u8 = hello as *const [u8] as *const u8;
157+
let ptr: *const i8 = hello as *const [u8] as *const i8;
158158
puts(ptr);
159159

160160
let world: Box<&str> = box "World!\0";
161-
puts(*world as *const str as *const u8);
161+
puts(*world as *const str as *const i8);
162162
world as Box<dyn SomeTrait>;
163163

164164
assert_eq!(intrinsics::bitreverse(0b10101000u8), 0b00010101u8);
@@ -242,13 +242,13 @@ fn main() {
242242
assert_eq!(((|()| 42u8) as fn(()) -> u8)(()), 42);
243243

244244
extern {
245-
#[linkage = "weak"]
245+
#[linkage = "extern_weak"]
246246
static ABC: *const u8;
247247
}
248248

249249
{
250250
extern {
251-
#[linkage = "weak"]
251+
#[linkage = "extern_weak"]
252252
static ABC: *const u8;
253253
}
254254
}
@@ -351,7 +351,7 @@ fn test_tls() {
351351
// TLS of main thread must not have been changed by the other thread.
352352
assert_eq!(TLS, 42);
353353

354-
puts("TLS works!\n\0" as *const str as *const u8);
354+
puts("TLS works!\n\0" as *const str as *const i8);
355355
}
356356
}
357357

0 commit comments

Comments
 (0)