microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.18.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/allocator/mimalloc-sys/build.rs

65lines · modeblame

93f01d0dIan Davis2 years ago1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use std::boxed::Box;
5use std::env;
6use std::error::Error;
7use std::fs;
91589c3aIan Davis2 years ago8use std::path::PathBuf;
93f01d0dIan Davis2 years ago9
10fn main() -> Result<(), Box<dyn Error>> {
91589c3aIan Davis2 years ago11compile_mimalloc();
12let build_dir = get_build_dir()?;
13println!(
14"cargo:rerun-if-changed={}",
15build_dir.join("mimalloc").display()
16);
93f01d0dIan Davis2 years ago17Ok(())
18}
19
20// Compile mimalloc source code and link it to the crate.
21// The cc crate is used to compile the source code into a static library.
22// We don't use the cmake crate to compile the source code because the mimalloc build system
23// loads extra libraries, changes the name and path around, and does other things that are
24// difficult to handle. The cc crate is much simpler and more predictable.
91589c3aIan Davis2 years ago25fn compile_mimalloc() {
26let mimalloc_vendor_dir = PathBuf::from("mimalloc");
93f01d0dIan Davis2 years ago27
28let mut build = cc::Build::new();
29
91589c3aIan Davis2 years ago30let include_dir = mimalloc_vendor_dir.join("include");
31let src_dir = mimalloc_vendor_dir.join("src");
32let static_file = src_dir.join("static.c");
33
34assert!(include_dir.exists(), "include_dir: {include_dir:?}");
35assert!(src_dir.exists(), "src_dir: {src_dir:?}");
36assert!(static_file.exists(), "static_file: {static_file:?}");
37
38build.include(include_dir);
39build.include(src_dir);
40build.file(static_file);
93f01d0dIan Davis2 years ago41
42if build.get_compiler().is_like_msvc() {
43build.static_crt(true);
44}
45// turn off debug mode
46build.define("MI_DEBUG", "0");
47
48// turning on optimizations doesn't seem to make a difference
49//build.opt_level(3);
50
f9675380Ian Davis2 years ago51// log the command that will be run
52build.cargo_debug(true);
53
54// turn off warnings from the mimalloc code
55build.cargo_warnings(false);
56
93f01d0dIan Davis2 years ago57build.compile("mimalloc");
58}
59
60fn get_build_dir() -> Result<PathBuf, Box<dyn Error>> {
61let manifest_dir = env::var("CARGO_MANIFEST_DIR")?;
62let build_dir = PathBuf::from(manifest_dir.as_str());
63let normalized_build_dir = fs::canonicalize(build_dir)?;
64Ok(normalized_build_dir)
65}