Skip to content

Commit 508b7b9

Browse files
committed
Move runtime files to C instead of C++
Explicitly have the only C++ portion of the runtime be one file with exception handling. All other runtime files must now live in C and be fully defined in C.
1 parent e8bf078 commit 508b7b9

12 files changed

+248
-208
lines changed

mk/clean.mk

+31-17
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@
1212
# Cleanup
1313
######################################################################
1414

15-
CLEAN_STAGE_RULES = \
16-
$(foreach stage, $(STAGES), \
17-
$(foreach host, $(CFG_HOST), \
15+
CLEAN_STAGE_RULES := \
16+
$(foreach stage, $(STAGES), \
17+
$(foreach host, $(CFG_HOST), \
1818
clean$(stage)_H_$(host) \
19-
$(foreach target, $(CFG_TARGET), \
19+
$(foreach target, $(CFG_TARGET), \
2020
clean$(stage)_T_$(target)_H_$(host))))
2121

22+
CLEAN_STAGE_RULES := $(CLEAN_STAGE_RULES) \
23+
$(foreach host, $(CFG_HOST), clean-generic-H-$(host))
24+
25+
CLEAN_STAGE_RULES := $(CLEAN_STAGE_RULES) \
26+
$(foreach host, $(CFG_TARGET), clean-generic-T-$(host))
27+
2228
CLEAN_LLVM_RULES = \
2329
$(foreach target, $(CFG_HOST), \
2430
clean-llvm$(target))
@@ -33,19 +39,6 @@ clean: clean-misc $(CLEAN_STAGE_RULES)
3339

3440
clean-misc:
3541
@$(call E, cleaning)
36-
$(Q)find $(CFG_BUILD)/rustllvm \
37-
$(CFG_BUILD)/rt \
38-
$(CFG_BUILD)/test \
39-
-name '*.[odasS]' -o \
40-
-name '*.so' -o \
41-
-name '*.dylib' -o \
42-
-name '*.dll' -o \
43-
-name '*.def' -o \
44-
-name '*.bc' \
45-
| xargs rm -f
46-
$(Q)find $(CFG_BUILD)\
47-
-name '*.dSYM' \
48-
| xargs rm -Rf
4942
$(Q)rm -f $(RUNTIME_OBJS) $(RUNTIME_DEF)
5043
$(Q)rm -f $(RUSTLLVM_LIB_OBJS) $(RUSTLLVM_OBJS_OBJS) $(RUSTLLVM_DEF)
5144
$(Q)rm -Rf $(DOCS)
@@ -60,6 +53,27 @@ clean-misc:
6053
$(Q)rm -Rf $(foreach sub, index styles files search javascript, \
6154
$(wildcard doc/*/$(sub)))
6255

56+
define CLEAN_GENERIC
57+
58+
clean-generic-$(2)-$(1):
59+
$(Q)find $(1)/rustllvm \
60+
$(1)/rt \
61+
$(1)/test \
62+
-name '*.[odasS]' -o \
63+
-name '*.so' -o \
64+
-name '*.dylib' -o \
65+
-name '*.dll' -o \
66+
-name '*.def' -o \
67+
-name '*.bc' \
68+
| xargs rm -f
69+
$(Q)find $(1)\
70+
-name '*.dSYM' \
71+
| xargs rm -Rf
72+
endef
73+
74+
$(foreach host, $(CFG_HOST), $(eval $(call CLEAN_GENERIC,$(host),H)))
75+
$(foreach targ, $(CFG_TARGET), $(eval $(call CLEAN_GENERIC,$(targ),T)))
76+
6377
define CLEAN_HOST_STAGE_N
6478

6579
clean$(1)_H_$(2):

mk/platform.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ CFG_LIB_GLOB_arm-apple-darwin = lib$(1)-*.dylib
206206
CFG_LIB_DSYM_GLOB_arm-apple-darwin = lib$(1)-*.dylib.dSYM
207207
CFG_GCCISH_CFLAGS_arm-apple-darwin := -Wall -Werror -g -fPIC $(CFG_IOS_FLAGS)
208208
CFG_GCCISH_CXXFLAGS_arm-apple-darwin := -fno-rtti $(CFG_IOS_FLAGS)
209-
CFG_GCCISH_LINK_FLAGS_arm-apple-darwin := -dynamiclib -lpthread -framework CoreServices -Wl,-no_compact_unwind
209+
CFG_GCCISH_LINK_FLAGS_arm-apple-darwin := -dynamiclib -lpthread -framework CoreServices -Wl,-no_compact_unwind
210210
CFG_GCCISH_DEF_FLAG_arm-apple-darwin := -Wl,-exported_symbols_list,
211211
CFG_GCCISH_PRE_LIB_FLAGS_arm-apple-darwin :=
212212
CFG_GCCISH_POST_LIB_FLAGS_arm-apple-darwin :=
@@ -506,7 +506,7 @@ define CFG_MAKE_TOOLCHAIN
506506
-c -o $$(1) $$(2)
507507
CFG_LINK_C_$(1) = $$(CC_$(1)) \
508508
$$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \
509-
$$(CFG_GCCISH_LINK_FLAGS_$(1))) \
509+
$$(CFG_GCCISH_LINK_FLAGS_$(1)) \
510510
$$(CFG_GCCISH_DEF_FLAG_$(1))$$(3) $$(2) \
511511
$$(call CFG_INSTALL_NAME_$(1),$$(4))
512512
CFG_COMPILE_CXX_$(1) = $$(CXX_$(1)) \

mk/rt.mk

+16-11
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,18 @@ endif
9090
endif
9191

9292
RUNTIME_CXXS_$(1)_$(2) := \
93-
rt/rust_builtin.cpp \
94-
rt/rust_upcall.cpp \
95-
rt/miniz.cpp \
96-
rt/rust_android_dummy.cpp \
97-
rt/rust_test_helpers.cpp
93+
rt/rust_cxx_glue.cpp
9894

99-
RUNTIME_CS_$(1)_$(2) :=
95+
RUNTIME_CS_$(1)_$(2) := \
96+
rt/rust_builtin.c \
97+
rt/rust_upcall.c \
98+
rt/miniz.c \
99+
rt/rust_android_dummy.c \
100+
rt/rust_test_helpers.c
101+
102+
# stage0 remove this after the next snapshot
103+
%.cpp:
104+
@touch tmp/foo.o
100105

101106
RUNTIME_S_$(1)_$(2) := rt/arch/$$(HOST_$(1))/_context.S \
102107
rt/arch/$$(HOST_$(1))/record_sp.S
@@ -114,7 +119,7 @@ ALL_OBJ_FILES += $$(RUNTIME_OBJS_$(1)_$(2))
114119
MORESTACK_OBJS_$(1)_$(2) := $$(RT_BUILD_DIR_$(1)_$(2))/arch/$$(HOST_$(1))/morestack.o
115120
ALL_OBJ_FILES += $$(MORESTACK_OBJS_$(1)_$(2))
116121

117-
$$(RT_BUILD_DIR_$(1)_$(2))/%.o: rt/%.cpp $$(MKFILE_DEPS)
122+
$$(RT_BUILD_DIR_$(1)_$(2))/rust_cxx_glue.o: rt/rust_cxx_glue.cpp $$(MKFILE_DEPS)
118123
@$$(call E, compile: $$@)
119124
$$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, $$(RUNTIME_INCS_$(1)_$(2)) \
120125
$$(SNAP_DEFINES) $$(RUNTIME_CXXFLAGS_$(1)_$(2))) $$<
@@ -241,13 +246,13 @@ endif
241246
UV_SUPPORT_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),uv_support)
242247
UV_SUPPORT_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/uv_support
243248
UV_SUPPORT_LIB_$(1) := $$(UV_SUPPORT_DIR_$(1))/$$(UV_SUPPORT_NAME_$(1))
244-
UV_SUPPORT_CS_$(1) := rt/rust_uv.cpp
245-
UV_SUPPORT_OBJS_$(1) := $$(UV_SUPPORT_CS_$(1):rt/%.cpp=$$(UV_SUPPORT_DIR_$(1))/%.o)
249+
UV_SUPPORT_CS_$(1) := rt/rust_uv.c
250+
UV_SUPPORT_OBJS_$(1) := $$(UV_SUPPORT_CS_$(1):rt/%.c=$$(UV_SUPPORT_DIR_$(1))/%.o)
246251

247-
$$(UV_SUPPORT_DIR_$(1))/%.o: rt/%.cpp
252+
$$(UV_SUPPORT_DIR_$(1))/%.o: rt/%.c
248253
@$$(call E, compile: $$@)
249254
@mkdir -p $$(@D)
250-
$$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, \
255+
$$(Q)$$(call CFG_COMPILE_C_$(1), $$@, \
251256
-I $$(S)src/libuv/include \
252257
$$(RUNTIME_CFLAGS_$(1))) $$<
253258

src/libstd/rt/args.rs

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) }
6363
#[cfg(target_os = "android")]
6464
#[cfg(target_os = "freebsd")]
6565
mod imp {
66+
use cast;
6667
use libc;
6768
use option::{Option, Some, None};
6869
use iter::Iterator;
File renamed without changes.

src/rt/rust_android_dummy.cpp renamed to src/rt/rust_android_dummy.c

+19-19
Original file line numberDiff line numberDiff line change
@@ -14,92 +14,92 @@ char **backtrace_symbols(void *const *array, int size) { return 0; }
1414

1515
void backtrace_symbols_fd (void *const *array, int size, int fd) {}
1616

17-
extern "C" volatile int* __errno_location() {
17+
volatile int* __errno_location() {
1818
return &errno;
1919
}
2020

21-
extern "C" float log2f(float f)
21+
float log2f(float f)
2222
{
2323
return logf( f ) / logf( 2 );
2424
}
2525

26-
extern "C" double log2( double n )
26+
double log2( double n )
2727
{
2828
return log( n ) / log( 2 );
2929
}
3030

31-
extern "C" void telldir()
31+
void telldir()
3232
{
3333
}
3434

35-
extern "C" void seekdir()
35+
void seekdir()
3636
{
3737
}
3838

39-
extern "C" void mkfifo()
39+
void mkfifo()
4040
{
4141
}
4242

43-
extern "C" void abs()
43+
void abs()
4444
{
4545
}
4646

47-
extern "C" void labs()
47+
void labs()
4848
{
4949
}
5050

51-
extern "C" void rand()
51+
void rand()
5252
{
5353
}
5454

55-
extern "C" void srand()
55+
void srand()
5656
{
5757
}
5858

59-
extern "C" void atof()
59+
void atof()
6060
{
6161
}
6262

63-
extern "C" int glob(const char *pattern,
63+
int glob(const char *pattern,
6464
int flags,
6565
int (*errfunc) (const char *epath, int eerrno),
6666
glob_t *pglob)
6767
{
6868
return 0;
6969
}
7070

71-
extern "C" void globfree(glob_t *pglob)
71+
void globfree(glob_t *pglob)
7272
{
7373
}
7474

75-
extern "C" int pthread_atfork(void (*prefork)(void),
75+
int pthread_atfork(void (*prefork)(void),
7676
void (*postfork_parent)(void),
7777
void (*postfork_child)(void))
7878
{
7979
return 0;
8080
}
8181

82-
extern "C" int mlockall(int flags)
82+
int mlockall(int flags)
8383
{
8484
return 0;
8585
}
8686

87-
extern "C" int munlockall(void)
87+
int munlockall(void)
8888
{
8989
return 0;
9090
}
9191

92-
extern "C" int shm_open(const char *name, int oflag, mode_t mode)
92+
int shm_open(const char *name, int oflag, mode_t mode)
9393
{
9494
return 0;
9595
}
9696

97-
extern "C" int shm_unlink(const char *name)
97+
int shm_unlink(const char *name)
9898
{
9999
return 0;
100100
}
101101

102-
extern "C" int posix_madvise(void *addr, size_t len, int advice)
102+
int posix_madvise(void *addr, size_t len, int advice)
103103
{
104104
return 0;
105105
}

0 commit comments

Comments
 (0)