Skip to content

Commit 98c771c

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

7 files changed

Lines changed: 180 additions & 101 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22

33
usecrate::artifact_names::{dynamic_lib_name, static_lib_name};
4-
usecrate::external_deps::cc::{cc, cxx};
4+
usecrate::external_deps::c_cxx_compiler::{cc, cxx};
55
usecrate::external_deps::llvm::llvm_ar;
66
usecrate::path_helpers::path;
77
usecrate::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

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

33
usecrate::command::Command;
4-
usecrate::{env_var, is_msvc, is_windows, uname};
4+
usecrate::{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-
pubfnextra_c_flags() -> Vec<&'staticstr>{
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-
ifis_windows(){
164-
ifis_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-
matchuname(){
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-
pubfnextra_cxx_flags() -> Vec<&'staticstr>{
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-
ifis_windows(){
217-
ifis_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-
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
usecrate::{is_msvc, is_windows, uname};
2+
3+
/// `EXTRACFLAGS`
4+
pubfnextra_c_flags() -> Vec<&'staticstr>{
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+
ifis_windows(){
36+
ifis_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+
matchuname(){
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+
pubfnextra_cxx_flags() -> Vec<&'staticstr>{
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+
ifis_windows(){
89+
ifis_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+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use std::path::Path;
2+
3+
usecrate::command::Command;
4+
usecrate::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+
pubfngcc() -> Gcc{
11+
Gcc::new()
12+
}
13+
14+
/// A specific `gcc`.
15+
#[derive(Debug)]
16+
#[must_use]
17+
pubstructGcc{
18+
cmd:Command,
19+
}
20+
21+
crate::macros::impl_common_helpers!(Gcc);
22+
23+
implGcc{
24+
/// Construct a `gcc` invocation. This assumes that *a* suitable `gcc` is available in the
25+
/// environment.
26+
#[track_caller]
27+
pubfnnew() -> Self{
28+
letmut 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+
pubfninput<P:AsRef<Path>>(&mutself,path:P) -> &mutSelf{
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+
pubfnlibrary_search_path<P:AsRef<Path>>(&mutself,path:P) -> &mutSelf{
47+
self.cmd.arg("-L");
48+
self.cmd.arg(path.as_ref());
49+
self
50+
}
51+
52+
/// Specify `-o`.
53+
pubfnout_exe(&mutself,name:&str) -> &mutSelf{
54+
self.cmd.arg("-o");
55+
self.cmd.arg(name);
56+
self
57+
}
58+
59+
/// Specify path of the output binary.
60+
pubfnoutput<P:AsRef<Path>>(&mutself,path:P) -> &mutSelf{
61+
self.cmd.arg("-o");
62+
self.cmd.arg(path.as_ref());
63+
self
64+
}
65+
66+
/// Optimize the output at `-O3`.
67+
pubfnoptimize(&mutself) -> &mutSelf{
68+
self.cmd.arg("-O3");
69+
self
70+
}
71+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
mod cc;
2+
mod extras;
3+
mod gcc;
4+
5+
pubuse cc::*;
6+
pubuse extras::*;
7+
pubuse gcc::*;

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

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

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

Lines changed: 2 additions & 2 deletions
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-
pubuse external_deps::{c_build,cc, clang, htmldocck, llvm, python, rustc, rustdoc};
49+
pubuse external_deps::{c_build,c_cxx_compiler, clang, htmldocck, llvm, python, rustc, rustdoc};
5050

5151
// These rely on external dependencies.
52-
pubusecc::{cc, cxx, extra_c_flags, extra_cxx_flags,Cc};
52+
pubusec_cxx_compiler::{Cc,Gcc,cc, cxx, extra_c_flags, extra_cxx_flags,gcc};
5353
pubuse 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)