Skip to content

Commit 98c771c

Browse files
committed
run_make_support: add a gcc wrapper command
1 parent fcba961 commit 98c771c

File tree

7 files changed

+180
-101
lines changed

7 files changed

+180
-101
lines changed

src/tools/run-make-support/src/external_deps/c_build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22

33
use crate::artifact_names::{dynamic_lib_name, static_lib_name};
4-
use crate::external_deps::cc::{cc, cxx};
4+
use crate::external_deps::c_cxx_compiler::{cc, cxx};
55
use crate::external_deps::llvm::llvm_ar;
66
use crate::path_helpers::path;
77
use crate::targets::{is_darwin, is_msvc, is_windows};

src/tools/run-make-support/src/external_deps/cc.rs renamed to src/tools/run-make-support/src/external_deps/c_cxx_compiler/cc.rs

+1-97
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::Path;
22

33
use crate::command::Command;
4-
use crate::{env_var, is_msvc, is_windows, uname};
4+
use crate::{env_var, is_msvc};
55

66
/// Construct a new platform-specific C compiler invocation.
77
///
@@ -127,99 +127,3 @@ impl Cc {
127127
self
128128
}
129129
}
130-
131-
/// `EXTRACFLAGS`
132-
pub fn extra_c_flags() -> Vec<&'static str> {
133-
// Adapted from tools.mk (trimmed):
134-
//
135-
// ```makefile
136-
// ifdef IS_WINDOWS
137-
// ifdef IS_MSVC
138-
// EXTRACFLAGS := ws2_32.lib userenv.lib advapi32.lib bcrypt.lib ntdll.lib synchronization.lib
139-
// else
140-
// EXTRACFLAGS := -lws2_32 -luserenv -lbcrypt -lntdll -lsynchronization
141-
// endif
142-
// else
143-
// ifeq ($(UNAME),Darwin)
144-
// EXTRACFLAGS := -lresolv
145-
// else
146-
// ifeq ($(UNAME),FreeBSD)
147-
// EXTRACFLAGS := -lm -lpthread -lgcc_s
148-
// else
149-
// ifeq ($(UNAME),SunOS)
150-
// EXTRACFLAGS := -lm -lpthread -lposix4 -lsocket -lresolv
151-
// else
152-
// ifeq ($(UNAME),OpenBSD)
153-
// EXTRACFLAGS := -lm -lpthread -lc++abi
154-
// else
155-
// EXTRACFLAGS := -lm -lrt -ldl -lpthread
156-
// endif
157-
// endif
158-
// endif
159-
// endif
160-
// endif
161-
// ```
162-
163-
if is_windows() {
164-
if is_msvc() {
165-
vec![
166-
"ws2_32.lib",
167-
"userenv.lib",
168-
"advapi32.lib",
169-
"bcrypt.lib",
170-
"ntdll.lib",
171-
"synchronization.lib",
172-
]
173-
} else {
174-
vec!["-lws2_32", "-luserenv", "-lbcrypt", "-lntdll", "-lsynchronization"]
175-
}
176-
} else {
177-
match uname() {
178-
n if n.contains("Darwin") => vec!["-lresolv"],
179-
n if n.contains("FreeBSD") => vec!["-lm", "-lpthread", "-lgcc_s"],
180-
n if n.contains("SunOS") => {
181-
vec!["-lm", "-lpthread", "-lposix4", "-lsocket", "-lresolv"]
182-
}
183-
n if n.contains("OpenBSD") => vec!["-lm", "-lpthread", "-lc++abi"],
184-
_ => vec!["-lm", "-lrt", "-ldl", "-lpthread"],
185-
}
186-
}
187-
}
188-
189-
/// `EXTRACXXFLAGS`
190-
pub fn extra_cxx_flags() -> Vec<&'static str> {
191-
// Adapted from tools.mk (trimmed):
192-
//
193-
// ```makefile
194-
// ifdef IS_WINDOWS
195-
// ifdef IS_MSVC
196-
// else
197-
// EXTRACXXFLAGS := -lstdc++
198-
// endif
199-
// else
200-
// ifeq ($(UNAME),Darwin)
201-
// EXTRACXXFLAGS := -lc++
202-
// else
203-
// ifeq ($(UNAME),FreeBSD)
204-
// else
205-
// ifeq ($(UNAME),SunOS)
206-
// else
207-
// ifeq ($(UNAME),OpenBSD)
208-
// else
209-
// EXTRACXXFLAGS := -lstdc++
210-
// endif
211-
// endif
212-
// endif
213-
// endif
214-
// endif
215-
// ```
216-
if is_windows() {
217-
if is_msvc() { vec![] } else { vec!["-lstdc++"] }
218-
} else {
219-
match &uname()[..] {
220-
"Darwin" => vec!["-lc++"],
221-
"FreeBSD" | "SunOS" | "OpenBSD" => vec![],
222-
_ => vec!["-lstdc++"],
223-
}
224-
}
225-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
use crate::{is_msvc, is_windows, uname};
2+
3+
/// `EXTRACFLAGS`
4+
pub fn extra_c_flags() -> Vec<&'static str> {
5+
// Adapted from tools.mk (trimmed):
6+
//
7+
// ```makefile
8+
// ifdef IS_WINDOWS
9+
// ifdef IS_MSVC
10+
// EXTRACFLAGS := ws2_32.lib userenv.lib advapi32.lib bcrypt.lib ntdll.lib synchronization.lib
11+
// else
12+
// EXTRACFLAGS := -lws2_32 -luserenv -lbcrypt -lntdll -lsynchronization
13+
// endif
14+
// else
15+
// ifeq ($(UNAME),Darwin)
16+
// EXTRACFLAGS := -lresolv
17+
// else
18+
// ifeq ($(UNAME),FreeBSD)
19+
// EXTRACFLAGS := -lm -lpthread -lgcc_s
20+
// else
21+
// ifeq ($(UNAME),SunOS)
22+
// EXTRACFLAGS := -lm -lpthread -lposix4 -lsocket -lresolv
23+
// else
24+
// ifeq ($(UNAME),OpenBSD)
25+
// EXTRACFLAGS := -lm -lpthread -lc++abi
26+
// else
27+
// EXTRACFLAGS := -lm -lrt -ldl -lpthread
28+
// endif
29+
// endif
30+
// endif
31+
// endif
32+
// endif
33+
// ```
34+
35+
if is_windows() {
36+
if is_msvc() {
37+
vec![
38+
"ws2_32.lib",
39+
"userenv.lib",
40+
"advapi32.lib",
41+
"bcrypt.lib",
42+
"ntdll.lib",
43+
"synchronization.lib",
44+
]
45+
} else {
46+
vec!["-lws2_32", "-luserenv", "-lbcrypt", "-lntdll", "-lsynchronization"]
47+
}
48+
} else {
49+
match uname() {
50+
n if n.contains("Darwin") => vec!["-lresolv"],
51+
n if n.contains("FreeBSD") => vec!["-lm", "-lpthread", "-lgcc_s"],
52+
n if n.contains("SunOS") => {
53+
vec!["-lm", "-lpthread", "-lposix4", "-lsocket", "-lresolv"]
54+
}
55+
n if n.contains("OpenBSD") => vec!["-lm", "-lpthread", "-lc++abi"],
56+
_ => vec!["-lm", "-lrt", "-ldl", "-lpthread"],
57+
}
58+
}
59+
}
60+
61+
/// `EXTRACXXFLAGS`
62+
pub fn extra_cxx_flags() -> Vec<&'static str> {
63+
// Adapted from tools.mk (trimmed):
64+
//
65+
// ```makefile
66+
// ifdef IS_WINDOWS
67+
// ifdef IS_MSVC
68+
// else
69+
// EXTRACXXFLAGS := -lstdc++
70+
// endif
71+
// else
72+
// ifeq ($(UNAME),Darwin)
73+
// EXTRACXXFLAGS := -lc++
74+
// else
75+
// ifeq ($(UNAME),FreeBSD)
76+
// else
77+
// ifeq ($(UNAME),SunOS)
78+
// else
79+
// ifeq ($(UNAME),OpenBSD)
80+
// else
81+
// EXTRACXXFLAGS := -lstdc++
82+
// endif
83+
// endif
84+
// endif
85+
// endif
86+
// endif
87+
// ```
88+
if is_windows() {
89+
if is_msvc() { vec![] } else { vec!["-lstdc++"] }
90+
} else {
91+
match &uname()[..] {
92+
"Darwin" => vec!["-lc++"],
93+
"FreeBSD" | "SunOS" | "OpenBSD" => vec![],
94+
_ => vec!["-lstdc++"],
95+
}
96+
}
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use std::path::Path;
2+
3+
use crate::command::Command;
4+
use crate::env_var;
5+
6+
/// Construct a gcc invocation.
7+
///
8+
/// WARNING: This assumes *a* `gcc` exists in the environment and is suitable for use.
9+
#[track_caller]
10+
pub fn gcc() -> Gcc {
11+
Gcc::new()
12+
}
13+
14+
/// A specific `gcc`.
15+
#[derive(Debug)]
16+
#[must_use]
17+
pub struct Gcc {
18+
cmd: Command,
19+
}
20+
21+
crate::macros::impl_common_helpers!(Gcc);
22+
23+
impl Gcc {
24+
/// Construct a `gcc` invocation. This assumes that *a* suitable `gcc` is available in the
25+
/// environment.
26+
#[track_caller]
27+
pub fn new() -> Self {
28+
let mut cmd = Command::new("gcc");
29+
30+
let default_cflags = env_var("CC_DEFAULT_FLAGS");
31+
for flag in default_cflags.split(char::is_whitespace) {
32+
cmd.arg(flag);
33+
}
34+
35+
Self { cmd }
36+
}
37+
38+
/// Specify path of the input file.
39+
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
40+
self.cmd.arg(path.as_ref());
41+
self
42+
}
43+
44+
/// Adds directories to the list that the linker searches for libraries.
45+
/// Equivalent to `-L`.
46+
pub fn library_search_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
47+
self.cmd.arg("-L");
48+
self.cmd.arg(path.as_ref());
49+
self
50+
}
51+
52+
/// Specify `-o`.
53+
pub fn out_exe(&mut self, name: &str) -> &mut Self {
54+
self.cmd.arg("-o");
55+
self.cmd.arg(name);
56+
self
57+
}
58+
59+
/// Specify path of the output binary.
60+
pub fn output<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
61+
self.cmd.arg("-o");
62+
self.cmd.arg(path.as_ref());
63+
self
64+
}
65+
66+
/// Optimize the output at `-O3`.
67+
pub fn optimize(&mut self) -> &mut Self {
68+
self.cmd.arg("-O3");
69+
self
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
mod cc;
2+
mod extras;
3+
mod gcc;
4+
5+
pub use cc::*;
6+
pub use extras::*;
7+
pub use gcc::*;

src/tools/run-make-support/src/external_deps/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//! such as `cc` or `python`.
33
44
pub mod c_build;
5+
pub mod c_cxx_compiler;
56
pub mod cargo;
6-
pub mod cc;
77
pub mod clang;
88
pub mod htmldocck;
99
pub mod llvm;

src/tools/run-make-support/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ pub use wasmparser;
4646
// tidy-alphabetical-end
4747

4848
// Re-exports of external dependencies.
49-
pub use external_deps::{c_build, cc, clang, htmldocck, llvm, python, rustc, rustdoc};
49+
pub use external_deps::{c_build, c_cxx_compiler, clang, htmldocck, llvm, python, rustc, rustdoc};
5050

5151
// These rely on external dependencies.
52-
pub use cc::{cc, cxx, extra_c_flags, extra_cxx_flags, Cc};
52+
pub use c_cxx_compiler::{Cc, Gcc, cc, cxx, extra_c_flags, extra_cxx_flags, gcc};
5353
pub use c_build::{
5454
build_native_dynamic_lib, build_native_static_lib, build_native_static_lib_cxx,
5555
build_native_static_lib_optimized,

0 commit comments

Comments
 (0)