1 use support
::{basic_bin_manifest, basic_manifest, cross_compile, project}
;
2 use support
::{is_nightly, rustc_host}
;
6 if cross_compile
::disabled() {
25 assert_eq!(std::env::var("TARGET").unwrap(), "{}");
28 cross_compile
::alternate()
36 assert_eq!(env::consts::ARCH, "{}");
39 cross_compile
::alternate_arch()
43 let target
= cross_compile
::alternate();
44 p
.cargo("build -v --target").arg(&target
).run();
45 assert
!(p
.target_bin(&target
, "foo").is_file());
47 p
.process(&p
.target_bin(&target
, "foo")).run();
51 fn simple_cross_config() {
52 if cross_compile
::disabled() {
64 cross_compile
::alternate()
80 assert_eq!(std::env::var("TARGET").unwrap(), "{}");
83 cross_compile
::alternate()
91 assert_eq!(env::consts::ARCH, "{}");
94 cross_compile
::alternate_arch()
98 let target
= cross_compile
::alternate();
99 p
.cargo("build -v").run();
100 assert
!(p
.target_bin(&target
, "foo").is_file());
102 p
.process(&p
.target_bin(&target
, "foo")).run();
107 if cross_compile
::disabled() {
123 ).file("src/main.rs", "extern crate bar; fn main() { bar::bar(); }")
127 .file("Cargo.toml", &basic_manifest("bar", "0.0.1"))
128 .file("src/lib.rs", "pub fn bar() {}")
131 let target
= cross_compile
::alternate();
132 p
.cargo("build --target").arg(&target
).run();
133 assert
!(p
.target_bin(&target
, "foo").is_file());
135 p
.process(&p
.target_bin(&target
, "foo")).run();
140 if cross_compile
::disabled() {
169 assert_eq!(bar!(), baz::baz());
190 #![feature(plugin_registrar, rustc_private)]
192 extern crate rustc_plugin;
195 use rustc_plugin::Registry;
196 use syntax::tokenstream::TokenTree;
197 use syntax::source_map::Span;
199 use syntax::ext::base::{ExtCtxt, MacEager, MacResult};
200 use syntax::ext::build::AstBuilder;
203 pub fn foo(reg: &mut Registry) {
204 reg.register_macro("bar", expand_bar);
207 fn expand_bar(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
208 -> Box<MacResult + 'static> {
209 MacEager::expr(cx.expr_lit(sp, LitKind::Int(1, LitIntType::Unsuffixed)))
215 .file("Cargo.toml", &basic_manifest("baz", "0.0.1"))
216 .file("src/lib.rs", "pub fn baz() -> i32 { 1 }")
219 let target
= cross_compile
::alternate();
220 foo
.cargo("build --target").arg(&target
).run();
221 assert
!(foo
.target_bin(&target
, "foo").is_file());
223 foo
.process(&foo
.target_bin(&target
, "foo")).run();
227 fn plugin_to_the_max() {
228 if cross_compile
::disabled() {
257 assert_eq!(bar!(), baz::baz());
281 #![feature(plugin_registrar, rustc_private)]
283 extern crate rustc_plugin;
287 use rustc_plugin::Registry;
288 use syntax::tokenstream::TokenTree;
289 use syntax::source_map::Span;
291 use syntax::ext::base::{ExtCtxt, MacEager, MacResult};
292 use syntax::ext::build::AstBuilder;
296 pub fn foo(reg: &mut Registry) {
297 reg.register_macro("bar", expand_bar);
300 fn expand_bar(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
301 -> Box<MacResult + 'static> {
302 let bar = Ident::from_str("baz");
303 let path = cx.path(sp, vec![bar.clone(), bar]);
304 MacEager::expr(cx.expr_call(sp, cx.expr_path(path), vec![]))
310 .file("Cargo.toml", &basic_manifest("baz", "0.0.1"))
311 .file("src/lib.rs", "pub fn baz() -> i32 { 1 }")
314 let target
= cross_compile
::alternate();
315 foo
.cargo("build -v --target").arg(&target
).run();
317 foo
.cargo("build -v --target").arg(&target
).run();
318 assert
!(foo
.target_bin(&target
, "foo").is_file());
320 foo
.process(&foo
.target_bin(&target
, "foo")).run();
325 if cross_compile
::disabled() {
329 let target
= cross_compile
::alternate();
337 linker = "my-linker-tool"
341 ).file("Cargo.toml", &basic_bin_manifest("foo"))
348 assert_eq!(env::consts::ARCH, "{}");
351 cross_compile
::alternate_arch()
355 p
.cargo("build -v --target")
358 .with_stderr_contains(&format
!(
360 [COMPILING] foo v0.5.0 (CWD)
361 [RUNNING] `rustc --crate-name foo src/foo.rs --crate-type bin \
362 --emit=dep-info,link -C debuginfo=2 \
364 --out-dir CWD/target/{target}/debug/deps \
366 -C ar=my-ar-tool -C linker=my-linker-tool \
367 -L dependency=CWD/target/{target}/debug/deps \
368 -L dependency=CWD/target/debug/deps`
375 fn plugin_with_extra_dylib_dep() {
376 if cross_compile
::disabled() {
424 #![feature(plugin_registrar, rustc_private)]
426 extern crate rustc_plugin;
429 use rustc_plugin::Registry;
432 pub fn foo(reg: &mut Registry) {
433 println!("{}", baz::baz());
449 crate_type = ["dylib"]
451 ).file("src/lib.rs", "pub fn baz() -> i32 { 1 }")
454 let target
= cross_compile
::alternate();
455 foo
.cargo("build --target").arg(&target
).run();
460 if cross_compile
::disabled() {
480 #[allow(unused_extern_crates)]
484 assert_eq!(env::consts::ARCH, "{}");
486 #[test] fn test() {{ main() }}
488 cross_compile
::alternate_arch()
495 pub fn foo() {{ assert_eq!(env::consts::ARCH, "{}"); }}
496 #[test] fn test_foo() {{ foo() }}
498 cross_compile::alternate_arch()
502 let target = cross_compile::alternate();
503 p.cargo("test
--target
")
505 .with_stderr(&format!(
507 [COMPILING
] foo v0
.0
.0 (CWD
)
508 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) in [..]
509 [RUNNING
] target
/{triple}
/debug
/deps
/foo
-[..][EXE
]
510 [RUNNING
] target
/{triple}
/debug
/deps
/bar
-[..][EXE
]",
512 )).with_stdout_contains("test test_foo
... ok
")
513 .with_stdout_contains("test test
... ok
")
518 fn no_cross_doctests() {
519 if cross_compile::disabled() {
528 //! extern crate foo;
536 [COMPILING
] foo v0
.0
.1 (CWD
)
537 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) in [..]
538 [RUNNING
] target
/debug
/deps
/foo
-[..][EXE
]
543 p.cargo("test
").with_stderr(&host_output).run();
546 let target = cross_compile::host();
547 p.cargo("test
--target
")
549 .with_stderr(&format!(
551 [COMPILING
] foo v0
.0
.1 (CWD
)
552 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) in [..]
553 [RUNNING
] target
/{triple}
/debug
/deps
/foo
-[..][EXE
]
560 let target = cross_compile::alternate();
561 p.cargo("test
--target
")
563 .with_stderr(&format!(
565 [COMPILING
] foo v0
.0
.1 (CWD
)
566 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) in [..]
567 [RUNNING
] target
/{triple}
/debug
/deps
/foo
-[..][EXE
]
574 fn simple_cargo_run() {
575 if cross_compile::disabled() {
586 assert_eq
!(env
::consts
::ARCH
, "{}");
589 cross_compile::alternate_arch()
593 let target = cross_compile::alternate();
594 p.cargo("run
--target
").arg(&target).run();
598 fn cross_with_a_build_script() {
599 if cross_compile::disabled() {
603 let target = cross_compile::alternate();
619 use std
::path
::PathBuf
;
621 assert_eq
!(env
::var("TARGET").unwrap(), "{0}");
622 let mut path
= PathBuf
::from(env
::var_os("OUT_DIR").unwrap());
623 assert_eq
!(path
.file_name().unwrap().to_str().unwrap(), "out");
625 assert
!(path
.file_name().unwrap().to_str().unwrap()
626 .starts_with("foo-"));
628 assert_eq
!(path
.file_name().unwrap().to_str().unwrap(), "build");
630 assert_eq
!(path
.file_name().unwrap().to_str().unwrap(), "debug");
632 assert_eq
!(path
.file_name().unwrap().to_str().unwrap(), "{0}");
634 assert_eq
!(path
.file_name().unwrap().to_str().unwrap(), "target");
639 ).file("src
/main
.rs
", "fn main() {}
")
642 p.cargo("build
-v
--target
")
644 .with_stderr(&format!(
646 [COMPILING
] foo v0
.0
.0 (CWD
)
647 [RUNNING
] `rustc
[..] build
.rs
[..] --out
-dir CWD
/target
/debug
/build
/foo
-[..]`
648 [RUNNING
] `CWD
/target
/debug
/build
/foo
-[..]/build
-script
-build`
649 [RUNNING
] `rustc
[..] src
/main
.rs
[..] --target {target}
[..]`
650 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) in [..]
657 fn build_script_needed_for_host_and_target() {
658 if cross_compile::disabled() {
662 let target = cross_compile::alternate();
663 let host = rustc_host();
676 [build
-dependencies
.d2
]
682 #[allow(unused_extern_crates)]
684 fn main() { d2::d2(); }
689 #[allow(unused_extern_crates)]
691 fn main() { d1::d1(); }
702 ).file("d1
/src
/lib
.rs
", "pub fn d1() {}
")
708 let target
= env
::var("TARGET").unwrap();
709 println
!("cargo:rustc-flags=-L /path/to/{}", target
);
726 #[allow(unused_extern_crates)]
728 pub fn d2() { d1::d1(); }
732 p.cargo("build
-v
--target
")
734 .with_stderr_contains(&"[COMPILING
] d1 v0
.0
.0 (CWD
/d1
)")
735 .with_stderr_contains(
736 "[RUNNING
] `rustc
[..] d1
/build
.rs
[..] --out
-dir CWD
/target
/debug
/build
/d1
-[..]`
",
738 .with_stderr_contains("[RUNNING
] `CWD
/target
/debug
/build
/d1
-[..]/build
-script
-build`
")
739 .with_stderr_contains("[RUNNING
] `rustc
[..] d1
/src
/lib
.rs
[..]`
")
740 .with_stderr_contains("[COMPILING
] d2 v0
.0
.0 (CWD
/d2
)")
741 .with_stderr_contains(&format!(
742 "[RUNNING
] `rustc
[..] d2
/src
/lib
.rs
[..] -L
/path
/to
/{host}`
",
744 )).with_stderr_contains("[COMPILING
] foo v0
.0
.0 (CWD
)")
745 .with_stderr_contains(&format!(
746 "[RUNNING
] `rustc
[..] build
.rs
[..] --out
-dir CWD
/target
/debug
/build
/foo
-[..] \
747 -L
/path
/to
/{host}`
",
749 )).with_stderr_contains(&format!(
751 [RUNNING
] `rustc
[..] src
/main
.rs
[..] --target {target}
[..] \
752 -L
/path
/to
/{target}`
",
758 fn build_deps_for_the_right_arch() {
759 if cross_compile::disabled() {
775 ).file("src
/main
.rs
", "extern crate d2
; fn main() {}
")
776 .file("d1
/Cargo
.toml
", &basic_manifest("d1
", "0.0.0"))
777 .file("d1
/src
/lib
.rs
", "pub fn d1() {}
")
787 [build
-dependencies
.d1
]
790 ).file("d2
/build
.rs
", "extern crate d1
; fn main() {}
")
791 .file("d2
/src
/lib
.rs
", "")
794 let target = cross_compile::alternate();
795 p.cargo("build
-v
--target
").arg(&target).run();
799 fn build_script_only_host() {
800 if cross_compile::disabled() {
814 [build
-dependencies
.d1
]
817 ).file("src
/main
.rs
", "fn main() {}
")
818 .file("build
.rs
", "extern crate d1
; fn main() {}
")
828 ).file("d1
/src
/lib
.rs
", "pub fn d1() {}
")
835 assert
!(env
::var("OUT_DIR").unwrap().replace("\\", "/")
836 .contains("target/debug/build/d1-"),
837 "bad: {:?}", env
::var("OUT_DIR"));
842 let target = cross_compile::alternate();
843 p.cargo("build
-v
--target
").arg(&target).run();
847 fn plugin_build_script_right_arch() {
848 if cross_compile::disabled() {
865 ).file("build
.rs
", "fn main() {}
")
866 .file("src
/lib
.rs
", "")
869 p.cargo("build
-v
--target
")
870 .arg(cross_compile::alternate())
873 [COMPILING
] foo v0
.0
.1 ([..])
874 [RUNNING
] `rustc
[..] build
.rs
[..]`
875 [RUNNING
] `
[..]/build
-script
-build`
876 [RUNNING
] `rustc
[..] src
/lib
.rs
[..]`
877 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) in [..]
883 fn build_script_with_platform_specific_dependencies() {
884 if cross_compile::disabled() {
888 let target = cross_compile::alternate();
889 let host = rustc_host();
900 [build
-dependencies
.d1
]
906 #[allow(unused_extern_crates)]
910 ).file("src
/lib
.rs
", "")
920 [target
.{}
.dependencies
]
921 d2
= {{ path = "../d2" }
}
927 "#[allow(unused_extern_crates)] extern crate d2;",
928 ).file("d2/Cargo.toml", &basic_manifest("d2", "0.0.0"))
929 .file("d2/src/lib.rs", "")
932 p.cargo("build -v --target")
934 .with_stderr(&format!(
936 [COMPILING] d2 v0.0.0 ([..])
937 [RUNNING
] `rustc
[..] d2
/src
/lib
.rs
[..]`
938 [COMPILING
] d1 v0
.0
.0 ([..])
939 [RUNNING
] `rustc
[..] d1
/src
/lib
.rs
[..]`
940 [COMPILING
] foo v0
.0
.1 ([..])
941 [RUNNING
] `rustc
[..] build
.rs
[..]`
942 [RUNNING
] `CWD
/target
/debug
/build
/foo
-[..]/build
-script
-build`
943 [RUNNING
] `rustc
[..] src
/lib
.rs
[..] --target {target}
[..]`
944 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) in [..]
951 fn platform_specific_dependencies_do_not_leak() {
952 if cross_compile::disabled() {
956 let target = cross_compile::alternate();
957 let host = rustc_host();
971 [build
-dependencies
.d1
]
974 ).file("build
.rs
", "extern crate d1
; fn main() {}
")
975 .file("src
/lib
.rs
", "")
985 [target
.{}
.dependencies
]
986 d2
= {{ path = "../d2" }
}
990 ).file("d1
/src
/lib
.rs
", "extern crate d2
;")
991 .file("d1
/Cargo
.toml
", &basic_manifest("d1
", "0.0.0"))
992 .file("d2
/src
/lib
.rs
", "")
995 p.cargo("build
-v
--target
")
998 .with_stderr_contains("[..] can't find
crate for `d2`
[..]")
1003 fn platform_specific_variables_reflected_in_build_scripts() {
1004 if cross_compile::disabled() {
1008 let target = cross_compile::alternate();
1009 let host = rustc_host();
1021 [target
.{host}
.dependencies
]
1022 d1
= {{ path = "d1" }
}
1024 [target
.{target}
.dependencies
]
1025 d2
= {{ path = "d2" }
}
1037 let platform
= env
::var("TARGET").unwrap();
1038 let (expected
, not_expected
) = match &platform
[..] {{
1039 "{host}" => ("DEP_D1_VAL", "DEP_D2_VAL"),
1040 "{target}" => ("DEP_D2_VAL", "DEP_D1_VAL"),
1041 _
=> panic
!("unknown platform")
1044 env
::var(expected
).ok()
1045 .expect(&format
!("missing {{}}", expected
));
1046 env
::var(not_expected
).err()
1047 .expect(&format
!("found {{}}", not_expected
));
1053 ).file("src
/lib
.rs
", "")
1064 ).file("d1
/build
.rs
", r#"fn main() { println!("cargo:val=1") }
"#)
1065 .file("d1
/src
/lib
.rs
", "")
1076 ).file("d2
/build
.rs
", r#"fn main() { println!("cargo:val=1") }
"#)
1077 .file("d2
/src
/lib
.rs
", "")
1080 p.cargo("build
-v
").run();
1081 p.cargo("build
-v
--target
").arg(&target).run();
1085 fn cross_test_dylib() {
1086 if cross_compile::disabled() {
1090 let target = cross_compile::alternate();
1103 crate_type
= ["dylib"]
1111 extern crate bar
as the_bar
;
1113 pub fn bar() { the_bar::baz(); }
1121 extern crate foo
as the_foo
;
1124 fn foo() { the_foo::bar(); }
1136 crate_type
= ["dylib"]
1144 assert_eq
!(env
::consts
::ARCH
, "{}");
1147 cross_compile::alternate_arch()
1151 p.cargo("test
--target
")
1153 .with_stderr(&format!(
1155 [COMPILING
] bar v0
.0
.1 (CWD
/bar
)
1156 [COMPILING
] foo v0
.0
.1 (CWD
)
1157 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) in [..]
1158 [RUNNING
] target
/{arch}
/debug
/deps
/foo
-[..][EXE
]
1159 [RUNNING
] target
/{arch}
/debug
/deps
/test
-[..][EXE
]",
1160 arch = cross_compile::alternate()
1161 )).with_stdout_contains_n("test foo
... ok
", 2)