Skip to content

Commit 4af0bbf

Browse files
authored
Merge pull request #201 from udoprog/fix-no-std-build
Fix building no_std on Windows and Linux
2 parents 4ee4cf1 + 66700b4 commit 4af0bbf

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ jobs:
5454
no_std_build:
5555
name: NoStdBuild
5656
runs-on: ${{matrix.os}}
57-
# TODO: remove once build works.
58-
continue-on-error: true
57+
continue-on-error: ${{matrix.experimental}}
5958
strategy:
6059
matrix:
61-
os: [ubuntu-latest, windows-latest, macos-latest]
60+
include:
61+
- {os: ubuntu-latest, flags: "--profile unix -Z unstable-options", experimental: false}
62+
- {os: windows-latest, flags: "--profile windows -Z unstable-options", experimental: true}
63+
- {os: macos-latest, flags: "--profile macos -Z unstable-options", experimental: false}
6264
steps:
6365
- name: Checkout
6466
uses: actions/checkout@v2
@@ -71,4 +73,4 @@ jobs:
7173
uses: actions-rs/cargo@v1
7274
with:
7375
command: build
74-
args: --manifest-path=no_std/no_std_test/Cargo.toml
76+
args: --manifest-path=no_std/no_std_test/Cargo.toml ${{matrix.flags}}

no_std/no_std_test/Cargo.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cargo-features = ["named-profiles"]
2+
13
[package]
24
name = "no_std_test"
35
version = "0.1.0"
@@ -18,7 +20,17 @@ panic = "abort"
1820
opt-level = "z" # optimize for size
1921
debug = false
2022
rpath = false
21-
lto = "fat"
2223
debug-assertions = false
2324
codegen-units = 1
2425
panic = "abort"
26+
27+
[profile.unix]
28+
inherits = "release"
29+
lto = true
30+
31+
[profile.windows]
32+
inherits = "release"
33+
34+
[profile.macos]
35+
inherits = "release"
36+
lto = "fat"

no_std/no_std_test/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ To Compile
1212
The nightly compiler is required:
1313

1414
```bash
15-
cargo +nightly build --release
15+
cargo +nightly build --release --profile unix -Z unstable-features
1616
```
1717

18+
Available profiles are: `unix`, `windows` and `macos`.
19+
1820
The release build is optimized for size. It can be changed to optimize on speed instead.

no_std/no_std_test/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
//! a simple expression and uses the result as the return value.
33
44
#![no_std]
5-
#![feature(alloc_error_handler, start, core_intrinsics, lang_items)]
5+
#![feature(alloc_error_handler, start, core_intrinsics, lang_items, link_cfg)]
66

77
extern crate alloc;
88
extern crate wee_alloc;
99

1010
#[global_allocator]
1111
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
1212

13+
// NB: Rust needs a CRT runtime on Windows MSVC.
14+
#[cfg(all(windows, target_env = "msvc"))]
15+
#[link(name = "msvcrt")]
16+
#[link(name = "libcmt")]
17+
extern {}
18+
1319
use rhai::{Engine, INT};
1420

1521
#[start]

0 commit comments

Comments
 (0)