mirror of
https://github.com/denoland/deno.git
synced 2025-09-28 13:14:48 +00:00
build: make cargo build
work
This commit is contained in:
parent
3a31633041
commit
73e80b0763
6 changed files with 77 additions and 60 deletions
|
@ -8,9 +8,8 @@ clone_depth: 1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||||
CARGO_TARGET_DIR: $(APPVEYOR_BUILD_FOLDER)\target
|
|
||||||
DENO_BUILD_MODE: release
|
DENO_BUILD_MODE: release
|
||||||
DENO_BUILD_PATH: $(APPVEYOR_BUILD_FOLDER)\out\release
|
DENO_BUILD_PATH: $(APPVEYOR_BUILD_FOLDER)\target\release
|
||||||
DENO_THIRD_PARTY_PATH: $(APPVEYOR_BUILD_FOLDER)\third_party
|
DENO_THIRD_PARTY_PATH: $(APPVEYOR_BUILD_FOLDER)\third_party
|
||||||
MTIME_CACHE_DB: $(APPVEYOR_BUILD_FOLDER)\mtime_cache.xml
|
MTIME_CACHE_DB: $(APPVEYOR_BUILD_FOLDER)\mtime_cache.xml
|
||||||
RELEASE_ARTIFACT: deno_win_x64.zip
|
RELEASE_ARTIFACT: deno_win_x64.zip
|
||||||
|
@ -239,7 +238,6 @@ cache:
|
||||||
# Cache file mtimes in the main git repo, also to enable incremental builds.
|
# Cache file mtimes in the main git repo, also to enable incremental builds.
|
||||||
- $(MTIME_CACHE_DB)
|
- $(MTIME_CACHE_DB)
|
||||||
# Build incrementally.
|
# Build incrementally.
|
||||||
- $(CARGO_TARGET_DIR)
|
|
||||||
- $(DENO_BUILD_PATH)
|
- $(DENO_BUILD_PATH)
|
||||||
|
|
||||||
init:
|
init:
|
||||||
|
@ -328,7 +326,6 @@ install:
|
||||||
before_build:
|
before_build:
|
||||||
# Mark all files in the build dir 'not needed' until proven otherwise.
|
# Mark all files in the build dir 'not needed' until proven otherwise.
|
||||||
# TODO: also track files in third_party that aren't checked into the repo.
|
# TODO: also track files in third_party that aren't checked into the repo.
|
||||||
# TODO: also track files in $CARGO_TARGET_DIR.
|
|
||||||
- ps: Start-TraceFilesNeeded $env:DENO_BUILD_PATH -Recurse
|
- ps: Start-TraceFilesNeeded $env:DENO_BUILD_PATH -Recurse
|
||||||
|
|
||||||
# Download clang and gn, generate ninja files.
|
# Download clang and gn, generate ninja files.
|
||||||
|
@ -346,7 +343,7 @@ before_build:
|
||||||
build_script:
|
build_script:
|
||||||
- python tools\build.py
|
- python tools\build.py
|
||||||
- ps: Set-FilesNeeded -Auto -Reason "Build finished"
|
- ps: Set-FilesNeeded -Auto -Reason "Build finished"
|
||||||
- cargo check --release
|
- cargo build -vv --release
|
||||||
- ps: Set-FilesNeeded -Auto -Reason "Cargo check finished"
|
- ps: Set-FilesNeeded -Auto -Reason "Cargo check finished"
|
||||||
|
|
||||||
test_script:
|
test_script:
|
||||||
|
|
4
.gn
4
.gn
|
@ -30,8 +30,8 @@ default_args = {
|
||||||
# for now. See http://clang.llvm.org/docs/ControlFlowIntegrity.html
|
# for now. See http://clang.llvm.org/docs/ControlFlowIntegrity.html
|
||||||
is_cfi = false
|
is_cfi = false
|
||||||
|
|
||||||
# Disabled due to CRT linking problems in Windows when using prebuilt V8.
|
# TODO(ry) Remove this so debug builds can link faster. Currently removing
|
||||||
# Works in other configurations.
|
# this breaks cargo build in debug mode in OSX.
|
||||||
is_component_build = false
|
is_component_build = false
|
||||||
|
|
||||||
# Enable Jumbo build for a faster build.
|
# Enable Jumbo build for a faster build.
|
||||||
|
|
|
@ -80,7 +80,7 @@ script:
|
||||||
|
|
||||||
- |-
|
- |-
|
||||||
# Cargo check
|
# Cargo check
|
||||||
cargo check -j2 --release --locked
|
cargo build --release -vv -j2
|
||||||
|
|
||||||
before_deploy:
|
before_deploy:
|
||||||
- gzip -c target/release/deno > target/release/deno_${TRAVIS_OS_NAME}_x64.gz
|
- gzip -c target/release/deno > target/release/deno_${TRAVIS_OS_NAME}_x64.gz
|
||||||
|
|
9
BUILD.gn
9
BUILD.gn
|
@ -17,13 +17,6 @@ group("default") {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set of targets that need to be built for `cargo check` to succeed.
|
|
||||||
group("cargo_check_deps") {
|
|
||||||
deps = [
|
|
||||||
":msg_rs",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
main_extern = [
|
main_extern = [
|
||||||
"$rust_build:atty",
|
"$rust_build:atty",
|
||||||
"$rust_build:dirs",
|
"$rust_build:dirs",
|
||||||
|
@ -112,6 +105,8 @@ ts_sources = [
|
||||||
"third_party/yarn.lock",
|
"third_party/yarn.lock",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# When Cargo is driving the build, GN/Ninja are used to produce these non-Rust
|
||||||
|
# targets. Cargo handles all Rust source files and the final linking step.
|
||||||
group("deno_deps") {
|
group("deno_deps") {
|
||||||
deps = [
|
deps = [
|
||||||
":msg_rs",
|
":msg_rs",
|
||||||
|
|
84
build.rs
84
build.rs
|
@ -9,38 +9,23 @@ use std::path::{self, Path, PathBuf};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let gn_mode = if cfg!(target_os = "windows") {
|
||||||
|
// On Windows, we need to link with a release build of libdeno, because
|
||||||
|
// rust always uses the release CRT.
|
||||||
|
// TODO(piscisaureus): make linking with debug libdeno possible.
|
||||||
|
String::from("release")
|
||||||
|
} else {
|
||||||
// Cargo sets PROFILE to either "debug" or "release", which conveniently
|
// Cargo sets PROFILE to either "debug" or "release", which conveniently
|
||||||
// matches the build modes we support.
|
// matches the build modes we support.
|
||||||
let mode = env::var("PROFILE").unwrap();
|
env::var("PROFILE").unwrap()
|
||||||
|
|
||||||
let out_dir = env::var_os("OUT_DIR").unwrap();
|
|
||||||
let out_dir = env::current_dir().unwrap().join(out_dir);
|
|
||||||
|
|
||||||
// Normally we configure GN+Ninja to build into Cargo's OUT_DIR.
|
|
||||||
// However, when DENO_BUILD_PATH is set, perform the ninja build in that dir
|
|
||||||
// instead. This is used by CI to avoid building V8 etc twice.
|
|
||||||
let gn_out_dir = match env::var_os("DENO_BUILD_PATH") {
|
|
||||||
None => {
|
|
||||||
// out_dir looks like: "target/debug/build/deno-26d2b5325de0f0cf/out"
|
|
||||||
// The gn build is "target/debug"
|
|
||||||
// So we go up two directories. Blame cargo for these hacks.
|
|
||||||
let d = out_dir.parent().unwrap();
|
|
||||||
let d = d.parent().unwrap();
|
|
||||||
let d = d.parent().unwrap();
|
|
||||||
PathBuf::from(d)
|
|
||||||
}
|
|
||||||
Some(deno_build_path) => PathBuf::from(deno_build_path),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Give cargo some instructions. We do this first so the `rerun-if-*-changed`
|
let gn_out_dir = env::current_dir().unwrap();
|
||||||
// directives can take effect even if something the build itself fails.
|
let gn_out_dir = gn_out_dir.join(format!("target/{}", gn_mode));
|
||||||
println!("cargo:rustc-env=GN_OUT_DIR={}", normalize_path(&gn_out_dir));
|
let gn_out_dir = normalize_path(gn_out_dir);
|
||||||
println!(
|
|
||||||
"cargo:rustc-link-search=native={}/obj",
|
|
||||||
normalize_path(&gn_out_dir)
|
|
||||||
);
|
|
||||||
println!("cargo:rustc-link-lib=static=deno_deps");
|
|
||||||
|
|
||||||
|
// Tell Cargo when to re-run this file. We do this first, so these directives
|
||||||
|
// can take effect even if something goes wrong later in the build process.
|
||||||
println!("cargo:rerun-if-env-changed=DENO_BUILD_PATH");
|
println!("cargo:rerun-if-env-changed=DENO_BUILD_PATH");
|
||||||
// TODO: this is obviously not appropriate here.
|
// TODO: this is obviously not appropriate here.
|
||||||
println!("cargo:rerun-if-env-changed=APPVEYOR_REPO_COMMIT");
|
println!("cargo:rerun-if-env-changed=APPVEYOR_REPO_COMMIT");
|
||||||
|
@ -55,21 +40,45 @@ fn main() {
|
||||||
.map(|s| s.starts_with("rls"))
|
.map(|s| s.starts_with("rls"))
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
// If we're being invoked by the RLS, build only the targets that are needed
|
// This helps Rust source files locate the snapshot, source map etc.
|
||||||
// for `cargo check` to succeed.
|
println!("cargo:rustc-env=GN_OUT_DIR={}", gn_out_dir);
|
||||||
let gn_target = if check_only {
|
|
||||||
"cargo_check_deps"
|
let gn_target;
|
||||||
} else {
|
|
||||||
"deno_deps"
|
|
||||||
};
|
|
||||||
|
|
||||||
if check_only {
|
if check_only {
|
||||||
|
// When RLS is running "cargo check" to analyze the source code, we're not
|
||||||
|
// trying to build a working executable, rather we're just compiling all
|
||||||
|
// rust code. Therefore, make ninja build only 'msg_generated.rs'.
|
||||||
|
gn_target = "msg_rs";
|
||||||
|
|
||||||
|
// Enable the 'check_only' feature, which enables some workarounds in the
|
||||||
|
// rust source code to compile successfully without a bundle and snapshot
|
||||||
println!("cargo:rustc-cfg=feature=\"check-only\"");
|
println!("cargo:rustc-cfg=feature=\"check-only\"");
|
||||||
|
} else {
|
||||||
|
// "Full" (non-RLS) build.
|
||||||
|
gn_target = "deno_deps";
|
||||||
|
|
||||||
|
// Link with libdeno.a/.lib, which includes V8.
|
||||||
|
println!("cargo:rustc-link-search=native={}/obj/libdeno", gn_out_dir);
|
||||||
|
if cfg!(target_os = "windows") {
|
||||||
|
println!("cargo:rustc-link-lib=static=libdeno");
|
||||||
|
} else {
|
||||||
|
println!("cargo:rustc-link-lib=static=deno");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Link the system libraries that libdeno and V8 depend on.
|
||||||
|
if cfg!(any(target_os = "macos", target_os = "freebsd")) {
|
||||||
|
println!("cargo:rustc-link-lib=dylib=c++");
|
||||||
|
} else if cfg!(target_os = "windows") {
|
||||||
|
for lib in vec!["dbghelp", "shlwapi", "winmm", "ws2_32"] {
|
||||||
|
println!("cargo:rustc-link-lib={}", lib);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let status = Command::new("python")
|
let status = Command::new("python")
|
||||||
.env("DENO_BUILD_PATH", &gn_out_dir)
|
.env("DENO_BUILD_PATH", &gn_out_dir)
|
||||||
.env("DENO_BUILD_MODE", &mode)
|
.env("DENO_BUILD_MODE", &gn_mode)
|
||||||
.arg("./tools/setup.py")
|
.arg("./tools/setup.py")
|
||||||
.status()
|
.status()
|
||||||
.expect("setup.py failed");
|
.expect("setup.py failed");
|
||||||
|
@ -77,7 +86,7 @@ fn main() {
|
||||||
|
|
||||||
let status = Command::new("python")
|
let status = Command::new("python")
|
||||||
.env("DENO_BUILD_PATH", &gn_out_dir)
|
.env("DENO_BUILD_PATH", &gn_out_dir)
|
||||||
.env("DENO_BUILD_MODE", &mode)
|
.env("DENO_BUILD_MODE", &gn_mode)
|
||||||
.arg("./tools/build.py")
|
.arg("./tools/build.py")
|
||||||
.arg(gn_target)
|
.arg(gn_target)
|
||||||
.arg("-v")
|
.arg("-v")
|
||||||
|
@ -88,8 +97,9 @@ fn main() {
|
||||||
|
|
||||||
// Utility function to make a path absolute, normalizing it to use forward
|
// Utility function to make a path absolute, normalizing it to use forward
|
||||||
// slashes only. The returned value is an owned String, otherwise panics.
|
// slashes only. The returned value is an owned String, otherwise panics.
|
||||||
fn normalize_path(path: &Path) -> String {
|
fn normalize_path<T: AsRef<Path>>(path: T) -> String {
|
||||||
path
|
path
|
||||||
|
.as_ref()
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_owned()
|
.to_owned()
|
||||||
|
|
|
@ -16,23 +16,37 @@ config("deno_config") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v8_static_library("v8") {
|
# The `/Zl` ("omit default library name") flag makes the compiler produce object
|
||||||
public_deps = [
|
# files that can link with both static and dynamic libc.
|
||||||
"//build/win:default_exe_manifest",
|
config("win_crt_agnostic") {
|
||||||
|
if (is_win) {
|
||||||
|
cflags = [ "/Zl" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
v8_source_set("v8") {
|
||||||
|
configs = [
|
||||||
|
":deno_config",
|
||||||
|
":win_crt_agnostic",
|
||||||
|
]
|
||||||
|
deps = [
|
||||||
"//third_party/v8:v8",
|
"//third_party/v8:v8",
|
||||||
"//third_party/v8:v8_libbase",
|
"//third_party/v8:v8_libbase",
|
||||||
"//third_party/v8:v8_libplatform",
|
"//third_party/v8:v8_libplatform",
|
||||||
"//third_party/v8:v8_libsampler",
|
"//third_party/v8:v8_libsampler",
|
||||||
]
|
]
|
||||||
configs = [ ":deno_config" ]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Only functionality needed for libdeno_test and snapshot_creator
|
# Only functionality needed for libdeno_test and snapshot_creator
|
||||||
# In particular no flatbuffers, no assets, no rust, no msg handlers.
|
# In particular no flatbuffers, no assets, no rust, no msg handlers.
|
||||||
# Because snapshots are slow, it's important that snapshot_creator's
|
# Because snapshots are slow, it's important that snapshot_creator's
|
||||||
# dependencies are minimal.
|
# dependencies are minimal.
|
||||||
|
# The cargo-driven build links with libdeno to pull in all non-rust code.
|
||||||
v8_static_library("libdeno") {
|
v8_static_library("libdeno") {
|
||||||
configs = [ ":deno_config" ]
|
configs = [
|
||||||
|
":deno_config",
|
||||||
|
":win_crt_agnostic",
|
||||||
|
]
|
||||||
sources = [
|
sources = [
|
||||||
"api.cc",
|
"api.cc",
|
||||||
"binding.cc",
|
"binding.cc",
|
||||||
|
@ -41,8 +55,9 @@ v8_static_library("libdeno") {
|
||||||
"file_util.h",
|
"file_util.h",
|
||||||
"internal.h",
|
"internal.h",
|
||||||
]
|
]
|
||||||
public_deps = [
|
deps = [
|
||||||
":v8",
|
":v8",
|
||||||
|
"//build/config:shared_library_deps",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue