Merge pull request #201 from udoprog/fix-no-std-build

Fix building no_std on Windows and Linux
This commit is contained in:
Stephen Chung 2020-07-25 18:29:21 +08:00 committed by GitHub
commit 4af0bbf6d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 7 deletions

View File

@ -54,11 +54,13 @@ jobs:
no_std_build: no_std_build:
name: NoStdBuild name: NoStdBuild
runs-on: ${{matrix.os}} runs-on: ${{matrix.os}}
# TODO: remove once build works. continue-on-error: ${{matrix.experimental}}
continue-on-error: true
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] include:
- {os: ubuntu-latest, flags: "--profile unix -Z unstable-options", experimental: false}
- {os: windows-latest, flags: "--profile windows -Z unstable-options", experimental: true}
- {os: macos-latest, flags: "--profile macos -Z unstable-options", experimental: false}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -71,4 +73,4 @@ jobs:
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: build command: build
args: --manifest-path=no_std/no_std_test/Cargo.toml args: --manifest-path=no_std/no_std_test/Cargo.toml ${{matrix.flags}}

View File

@ -1,3 +1,5 @@
cargo-features = ["named-profiles"]
[package] [package]
name = "no_std_test" name = "no_std_test"
version = "0.1.0" version = "0.1.0"
@ -18,7 +20,17 @@ panic = "abort"
opt-level = "z" # optimize for size opt-level = "z" # optimize for size
debug = false debug = false
rpath = false rpath = false
lto = "fat"
debug-assertions = false debug-assertions = false
codegen-units = 1 codegen-units = 1
panic = "abort" panic = "abort"
[profile.unix]
inherits = "release"
lto = true
[profile.windows]
inherits = "release"
[profile.macos]
inherits = "release"
lto = "fat"

View File

@ -12,7 +12,9 @@ To Compile
The nightly compiler is required: The nightly compiler is required:
```bash ```bash
cargo +nightly build --release cargo +nightly build --release --profile unix -Z unstable-features
``` ```
Available profiles are: `unix`, `windows` and `macos`.
The release build is optimized for size. It can be changed to optimize on speed instead. The release build is optimized for size. It can be changed to optimize on speed instead.

View File

@ -2,7 +2,7 @@
//! a simple expression and uses the result as the return value. //! a simple expression and uses the result as the return value.
#![no_std] #![no_std]
#![feature(alloc_error_handler, start, core_intrinsics, lang_items)] #![feature(alloc_error_handler, start, core_intrinsics, lang_items, link_cfg)]
extern crate alloc; extern crate alloc;
extern crate wee_alloc; extern crate wee_alloc;
@ -10,6 +10,12 @@ extern crate wee_alloc;
#[global_allocator] #[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
// NB: Rust needs a CRT runtime on Windows MSVC.
#[cfg(all(windows, target_env = "msvc"))]
#[link(name = "msvcrt")]
#[link(name = "libcmt")]
extern {}
use rhai::{Engine, INT}; use rhai::{Engine, INT};
#[start] #[start]