Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only include dependencies when binary feature is enabled #68

Merged
merged 4 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ repository = "https://github.com/rust-osdev/bootloader"
edition = "2018"
build = "build.rs"

[[bin]]
name = "bootloader"
required-features = ["binary"]

[dependencies]
xmas-elf = "0.6.2"
x86_64 = "0.7.2"
usize_conversions = "0.2.0"
fixedvec = "0.2.3"
xmas-elf = { version = "0.6.2", optional = true }
x86_64 = { version = "0.7.2", optional = true }
usize_conversions = { version = "0.2.0", optional = true }
fixedvec = { version = "0.2.3", optional = true }

[dependencies.font8x8]
version = "0.2.4"
Expand All @@ -21,10 +25,11 @@ features = ["unicode"]
optional = true

[build-dependencies]
llvm-tools = "0.1"
llvm-tools = { version = "0.1", optional = true }

[features]
default = []
binary = ["xmas-elf", "x86_64", "usize_conversions", "fixedvec", "llvm-tools"]
vga_320x200 = ["font8x8"]
recursive_page_table = []
map_physical_memory = []
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ As an example, you can build the bootloader with example kernel from the `exampl
cd example-kernel
cargo xbuild
cd ..
KERNEL=example-kernel/target/x86_64-example-kernel/debug/example-kernel cargo xbuild --release
KERNEL=example-kernel/target/x86_64-example-kernel/debug/example-kernel cargo xbuild --release --features binary
```

This results in a bootloader executable at `target/x86_64-bootloader.json/release/bootloader`. This executable is still an ELF file, which can't be run directly.
The `binary` feature is required to enable the dependencies required for compiling the bootloader executable. The command results in a bootloader executable at `target/x86_64-bootloader.json/release/bootloader`. This executable is still an ELF file, which can't be run directly.

## Run

Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ steps:
workingDirectory: test-kernel
displayName: 'Build Test Kernel'

- script: cargo xbuild --release
- script: cargo xbuild --bin bootloader --features binary --release
displayName: 'Build Bootloader'
env: { KERNEL: "test-kernel/target/x86_64-test-kernel/debug/test-kernel" }

Expand Down
20 changes: 12 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
use std::{
env,
fs::File,
io::Write,
path::{Path, PathBuf},
process::{self, Command},
};
#[cfg(not(feature = "binary"))]
fn main() {}

#[cfg(feature = "binary")]
fn main() {
use std::{
env,
fs::File,
io::Write,
path::{Path, PathBuf},
process::{self, Command},
};

let target = env::var("TARGET").expect("TARGET not set");
if Path::new(&target)
.file_stem()
.expect("target has no file stem")
!= "x86_64-bootloader"
{
return;
panic!("The bootloader must be compiled for the `x86_64-bootloader.json` target.");
}

let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR not set"));
Expand Down