Commit 12c5f83e authored by Yonggang Luo's avatar Yonggang Luo
Browse files

Win32 get to work.

parent a22cc53a
[config]
default_to_workspace = false
default_task_name = "build"
[env]
COMMON = "COMMON"
PROFILE_NAME = "${CARGO_MAKE_PROFILE}"
LIBRARY_EXTENSION = { source = "${CARGO_MAKE_RUST_TARGET_OS}", default_value = "so", mapping = {"linux" = "so", "macos" = "dylib", "windows" = "dll", "openbsd" = "so" } }
STAIC_LIBRARY_EXTENSION = { source = "${CARGO_MAKE_RUST_TARGET_OS}", default_value = "a", mapping = {"linux" = "a", "macos" = "a", "windows" = "lib", "openbsd" = "a" } }
LIBRARY_PREFIX = { source = "${CARGO_MAKE_RUST_TARGET_OS}", default_value = "lib", mapping = {"windows" = ""} }
BUILD_TYPE = { source = "${CARGO_MAKE_PROFILE}", default_value = "debug", mapping = {"production" = "release"} }
BUILD_TYPE_CARGO_ARG = { source = "${CARGO_MAKE_PROFILE}", default_value = "--target=${CARGO_MAKE_RUST_TARGET_TRIPLE}", mapping = {"production" = "--target=${CARGO_MAKE_RUST_TARGET_TRIPLE} --release"} }
TARGET_DIST_DIR = "target/dist/${CARGO_MAKE_RUST_TARGET_TRIPLE}-${BUILD_TYPE}"
CARGO_INCREMENTAL = 0
RUST_BACKTRACE = 1
[env.development]
IS_DEV = true
IS_PROD = false
[env.production]
IS_DEV = false
IS_PROD = true
[tasks.echo]
workspace=false
script_runner = "@shell"
script = [
'''
echo COMMON: ${COMMON}
echo PROFILE_NAME: ${PROFILE_NAME}
echo IS_DEV: ${IS_DEV}
echo IS_PROD: ${IS_PROD}
'''
]
[tasks.format]
disabled = true
install_crate = "rustfmt"
command = "cargo"
args = ["fmt", "--", "--emit=files"]
[tasks.clean]
disabled = true
command = "cargo"
args = ["clean"]
[tasks.test]
workspace=false
disabled = true
[tasks.build]
command = "rustc"
args = ["--version"]
dependencies = ["crt", "rulibc_make", "run_test"]
[tasks.crt]
workspace=false
script_runner = "@shell"
script = [
'''
mkdir -p "${TARGET_DIST_DIR}/lib"
cargo rustc ${BUILD_TYPE_CARGO_ARG} --manifest-path src/crt0/Cargo.toml ${CARGOFLAGS} -- --emit obj=${TARGET_DIST_DIR}/lib/${LIB_PREFIX}crt0.o -C panic=abort ${RUSTCFLAGS}
cargo rustc ${BUILD_TYPE_CARGO_ARG} --manifest-path src/crti/Cargo.toml ${CARGOFLAGS} -- --emit obj=${TARGET_DIST_DIR}/lib/${LIB_PREFIX}crti.o -C panic=abort ${RUSTCFLAGS}
cargo rustc ${BUILD_TYPE_CARGO_ARG} --manifest-path src/crtn/Cargo.toml ${CARGOFLAGS} -- --emit obj=${TARGET_DIST_DIR}/lib/${LIB_PREFIX}crtn.o -C panic=abort ${RUSTCFLAGS}
'''
]
[tasks.rulibc_make]
workspace=false
script_runner = "@shell"
script = [
'''
cargo build ${BUILD_TYPE_CARGO_ARG} ${CARGOFLAGS} -- ${RUSTCFLAGS}
'''
]
[tasks.run_test]
script_runner = "@shell"
script = [
'''
cd tests
cargo clean
cargo build ${BUILD_TYPE_CARGO_ARG}
'''
]
......@@ -32,3 +32,8 @@ The motivation for this project is:
use `git fetch --force` to sync with the main branch.
The release branch will keep stable
## Developing
```
cargo install --force cargo-make
cargo make
```
\ No newline at end of file
......@@ -21,3 +21,4 @@ report_todo = "Never"
report_fixme = "Never"
edition = "2018"
merge_imports = true
unstable_features = true
\ No newline at end of file
use alloc::vec::Vec;
use core::{intrinsics};
use core::ptr::null_mut;
use winapi::um::winuser::{MB_OK, MessageBoxW};
use crate::{
header::{stdio, stdlib},
......@@ -49,8 +51,16 @@ pub unsafe extern "C" fn relibc_start(argc: isize) -> ! {
unreachable!();
}
fn print_message(msg: &str) {
let wide: Vec<u16> = msg.encode_utf16().collect();
let ret = unsafe {
MessageBoxW(null_mut(), wide.as_ptr(), wide.as_ptr(), MB_OK)
};
}
#[no_mangle]
pub unsafe extern "C" fn mainCRTStartup() -> ! {
print_message("Hello, the world");
unreachable!();
}
......
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "cc"
version = "1.0.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed67cbde08356238e75fc4656be4749481eeffb09e19f320a25237d5221c985d"
[[package]]
name = "encoding"
version = "0.2.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec"
dependencies = [
"encoding-index-japanese",
"encoding-index-korean",
"encoding-index-simpchinese",
"encoding-index-singlebyte",
"encoding-index-tradchinese",
]
[[package]]
name = "encoding-index-japanese"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91"
dependencies = [
"encoding_index_tests",
]
[[package]]
name = "encoding-index-korean"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dc33fb8e6bcba213fe2f14275f0963fd16f0a02c878e3095ecfdf5bee529d81"
dependencies = [
"encoding_index_tests",
]
[[package]]
name = "encoding-index-simpchinese"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d87a7194909b9118fc707194baa434a4e3b0fb6a5a757c73c3adb07aa25031f7"
dependencies = [
"encoding_index_tests",
]
[[package]]
name = "encoding-index-singlebyte"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a"
dependencies = [
"encoding_index_tests",
]
[[package]]
name = "encoding-index-tradchinese"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18"
dependencies = [
"encoding_index_tests",
]
[[package]]
name = "encoding_index_tests"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
[[package]]
name = "librulibc_tests"
version = "0.1.1"
dependencies = [
"cc",
"encoding",
]
[package]
name = "librulibc_tests"
version = "0.1.1"
authors = ["Yonggang Luo <luoyonggang@gmail.com>"]
license = "MIT/Apache-2.0"
description = """
Tests for rulibc
"""
repository = "https://github.com/rulibc/rulibc"
keywords = ["core", "no_std", "io", "read", "write"]
include = [
"Cargo.toml",
"LICENSE-*",
"src/**/*.rs",
]
[build-dependencies]
cc = "1.0"
encoding = "0.2"
\ No newline at end of file
extern crate cc;
use std::env;
extern crate encoding;
use encoding::{all::GBK, DecoderTrap, Encoding};
use std::{fs, fs::DirEntry, path::Path};
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
let cargo_profile = std::env::var("PROFILE").unwrap();
let cargo_target = std::env::var("TARGET").unwrap();
let mut build = cc::Build::new();
let compiler = build.get_compiler();
let mut cmd = compiler.to_command();
let target_dir = format!(
"{}/../target/dist/{}-{}",
crate_dir, cargo_target, cargo_profile
);
let dist_tets_dir = format!("{}/tests", target_dir);
fs::create_dir(Path::new(&dist_tets_dir));
let executable_path_arg = format!("-out:{}/tests/args.exe", target_dir);
if compiler.is_like_msvc() {
cmd.arg(&format!("-I{}/../include", crate_dir))
.arg(&format!("-I{}/../target/include", crate_dir))
.arg("args.c")
.args(&["-link", "-NODEFAULTLIB"])
.arg(&format!("-LIBPATH:{}/lib", target_dir))
.args(&["rulibc.lib", "kernel32.lib"])
.arg(executable_path_arg);
}
let status = cmd.status();
let code = status.unwrap().code().unwrap();
if (code != 0) {
let output = cmd.output();
let s = output.unwrap().stdout;
let val = GBK.decode(&s, DecoderTrap::Replace);
panic!(
"process exited with: exit code:{} {} {:?} {:?}",
code, target_dir, val, cmd
);
}
}
//! Type aliases to C types like c_int for use with bindgen
//!
//! # MSRV
//!
//! This crate is guaranteed to compile on stable Rust 1.30.0 and up. It *might* compile with older
//! versions but that may change in any new patch release.
#![allow(non_camel_case_types)]
#![deny(warnings)]
#![no_std]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment