Skip to content

Commit 0ce1b2f

Browse files
committed
Statically link libuv to librustuv
Similarly to the previous commit, libuv is only used by this library, so there's no need for it to be linked into librustrt and available to all crates by default.
1 parent 7f31b07 commit 0ce1b2f

File tree

7 files changed

+52
-127
lines changed

7 files changed

+52
-127
lines changed

Makefile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,10 @@ config.stamp: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
625625
# new definitions), make sure definitions always precede their uses,
626626
# especially for the dependency lists of recipes.
627627

628+
include $(CFG_SRC_DIR)mk/rt.mk
628629
include $(CFG_SRC_DIR)mk/target.mk
629630
include $(CFG_SRC_DIR)mk/host.mk
630631
include $(CFG_SRC_DIR)mk/stage0.mk
631-
include $(CFG_SRC_DIR)mk/rt.mk
632632
include $(CFG_SRC_DIR)mk/rustllvm.mk
633633
include $(CFG_SRC_DIR)mk/tools.mk
634634
include $(CFG_SRC_DIR)mk/docs.mk

mk/rt.mk

+23-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ RUNTIME_CXXS_$(1)_$(2) := \
8787
rt/sync/rust_thread.cpp \
8888
rt/rust_builtin.cpp \
8989
rt/rust_upcall.cpp \
90-
rt/rust_uv.cpp \
9190
rt/miniz.cpp \
9291
rt/rust_android_dummy.cpp \
9392
rt/rust_test_helpers.cpp
@@ -101,8 +100,7 @@ RT_BUILD_DIR_$(1)_$(2) := $$(RT_OUTPUT_DIR_$(1))/stage$(2)
101100

102101
RUNTIME_DEF_$(1)_$(2) := $$(RT_OUTPUT_DIR_$(1))/rustrt$$(CFG_DEF_SUFFIX_$(1))
103102
RUNTIME_INCS_$(1)_$(2) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
104-
-I $$(S)src/rt/arch/$$(HOST_$(1)) \
105-
-I $$(S)src/libuv/include
103+
-I $$(S)src/rt/arch/$$(HOST_$(1))
106104
RUNTIME_OBJS_$(1)_$(2) := $$(RUNTIME_CXXS_$(1)_$(2):rt/%.cpp=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \
107105
$$(RUNTIME_CS_$(1)_$(2):rt/%.c=$$(RT_BUILD_DIR_$(1)_$(2))/%.o) \
108106
$$(RUNTIME_S_$(1)_$(2):rt/%.S=$$(RT_BUILD_DIR_$(1)_$(2))/%.o)
@@ -131,10 +129,9 @@ $$(RT_BUILD_DIR_$(1)_$(2))/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJS_
131129
$$(Q)$(AR_$(1)) rcs $$@ $$^
132130

133131
$$(RT_BUILD_DIR_$(1)_$(2))/$(CFG_RUNTIME_$(1)): $$(RUNTIME_OBJS_$(1)_$(2)) $$(MKFILE_DEPS) \
134-
$$(RUNTIME_DEF_$(1)_$(2)) $$(LIBUV_LIB_$(1))
132+
$$(RUNTIME_DEF_$(1)_$(2))
135133
@$$(call E, link: $$@)
136134
$$(Q)$$(call CFG_LINK_CXX_$(1),$$@, $$(RUNTIME_OBJS_$(1)_$(2)) \
137-
$$(LIBUV_LIB_$(1)) \
138135
$$(CFG_LIBUV_LINK_FLAGS_$(1)),$$(RUNTIME_DEF_$(1)_$(2)),$$(CFG_RUNTIME_$(1)))
139136

140137
# These could go in rt.mk or rustllvm.mk, they're needed for both.
@@ -234,6 +231,27 @@ $$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE_$(1))
234231
V=$$(VERBOSE)
235232
endif
236233

234+
# libuv support functionality (extra C/C++ that we need to use libuv)
235+
236+
UV_SUPPORT_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),uv_support)
237+
UV_SUPPORT_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/uv_support
238+
UV_SUPPORT_LIB_$(1) := $$(UV_SUPPORT_DIR_$(1))/$$(UV_SUPPORT_NAME_$(1))
239+
UV_SUPPORT_CS_$(1) := rt/rust_uv.cpp
240+
UV_SUPPORT_OBJS_$(1) := $$(UV_SUPPORT_CS_$(1):rt/%.cpp=$$(UV_SUPPORT_DIR_$(1))/%.o)
241+
242+
$$(UV_SUPPORT_DIR_$(1))/%.o: rt/%.cpp
243+
@$$(call E, compile: $$@)
244+
@mkdir -p $$(@D)
245+
$$(Q)$$(call CFG_COMPILE_CXX_$(1), $$@, \
246+
-I $$(S)src/libuv/include \
247+
$$(RUNTIME_CFLAGS_$(1))) $$<
248+
249+
$$(UV_SUPPORT_LIB_$(1)): $$(UV_SUPPORT_OBJS_$(1))
250+
@$$(call E, link: $$@)
251+
$$(Q)$$(AR_$(1)) rcs $$@ $$^
252+
253+
# sundown markdown library (used by librustdoc)
254+
237255
SUNDOWN_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),sundown)
238256
SUNDOWN_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/sundown
239257
SUNDOWN_LIB_$(1) := $$(SUNDOWN_DIR_$(1))/$$(SUNDOWN_NAME_$(1))

mk/target.mk

+10-2
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,15 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTUV_$(2)): \
7777
$$(LIBRUSTUV_CRATE) $$(LIBRUSTUV_INPUTS) \
7878
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
7979
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
80+
$$(LIBUV_LIB_$(2)) \
81+
$$(UV_SUPPORT_LIB_$(2)) \
8082
| $$(TLIB$(1)_T_$(2)_H_$(3))/
8183
@$$(call E, compile_and_link: $$@)
8284
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTUV_GLOB_$(2)),$$(notdir $$@))
83-
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) --out-dir $$(@D) $$< && touch $$@
85+
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) \
86+
-L $$(UV_SUPPORT_DIR_$(2)) \
87+
-L $$(dir $$(LIBUV_LIB_$(2))) \
88+
--out-dir $$(@D) $$< && touch $$@
8489
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTUV_GLOB_$(2)),$$(notdir $$@))
8590

8691
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(3)): \
@@ -117,13 +122,16 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(3)): \
117122
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) --out-dir $$(@D) $$< && touch $$@
118123
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTC_GLOB_$(2)),$$(notdir $$@))
119124

125+
# NOTE: after the next snapshot remove these '-L' flags
120126
$$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X_$(3)): \
121127
$$(DRIVER_CRATE) \
122128
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
123129
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(3)) \
124130
| $$(TBIN$(1)_T_$(2)_H_$(3))/
125131
@$$(call E, compile_and_link: $$@)
126-
$$(STAGE$(1)_T_$(2)_H_$(3)) --cfg rustc -o $$@ $$<
132+
$$(STAGE$(1)_T_$(2)_H_$(3)) --cfg rustc -o $$@ $$< \
133+
-L $$(UV_SUPPORT_DIR_$(2)) \
134+
-L $$(dir $$(LIBUV_LIB_$(2)))
127135
ifdef CFG_ENABLE_PAX_FLAGS
128136
@$$(call E, apply PaX flags: $$@)
129137
@"$(CFG_PAXCTL)" -cm "$$@"

mk/tests.mk

+5-2
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ $(3)/stage$(1)/test/rustuvtest-$(2)$$(X_$(2)): \
358358
$$(LIBRUSTUV_CRATE) $$(LIBRUSTUV_INPUTS) \
359359
$$(STDTESTDEP_$(1)_$(2)_$(3))
360360
@$$(call E, compile_and_link: $$@)
361-
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
361+
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test \
362+
-L $$(UV_SUPPORT_DIR_$(2)) \
363+
-L $$(dir $$(LIBUV_LIB_$(2)))
362364

363365
$(3)/stage$(1)/test/syntaxtest-$(2)$$(X_$(2)): \
364366
$$(LIBSYNTAX_CRATE) $$(LIBSYNTAX_INPUTS) \
@@ -392,7 +394,8 @@ $(3)/stage$(1)/test/rustdoctest-$(2)$$(X_$(2)): \
392394
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBSYNTAX_$(2)) \
393395
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
394396
@$$(call E, compile_and_link: $$@)
395-
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
397+
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test \
398+
-L $$(SUNDOWN_DIR_$(2))
396399

397400
endef
398401

src/librustc/lib/llvm.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ pub mod llvm {
304304
use super::debuginfo::*;
305305
use std::libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong};
306306

307-
#[link_args = "-Lrustllvm -lrustllvm"]
308-
#[link_name = "rustllvm"]
307+
#[link_args = "-lrustllvm"]
309308
extern {
310309
/* Create and destroy contexts. */
311310
pub fn LLVMContextCreate() -> ContextRef;

src/librustuv/uvll.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,8 @@ pub struct uv_err_data {
10031003
err_msg: ~str,
10041004
}
10051005

1006+
// uv_support is the result of compiling rust_uv.cpp
1007+
#[link_args = "-luv_support -luv"]
10061008
extern {
10071009

10081010
fn rust_uv_handle_size(type_: uintptr_t) -> size_t;
@@ -1172,3 +1174,13 @@ extern {
11721174
signum: c_int) -> c_int;
11731175
fn rust_uv_signal_stop(handle: *uv_signal_t) -> c_int;
11741176
}
1177+
1178+
// libuv requires various system libraries to successfully link on some
1179+
// platforms
1180+
#[cfg(target_os = "linux")]
1181+
#[link_args = "-lpthread"]
1182+
extern {}
1183+
1184+
#[cfg(target_os = "win32")]
1185+
#[link_args = "-lWs2_32 -lpsapi -liphlpapi"]
1186+
extern {}

src/rt/rustrt.def.in

-115
Original file line numberDiff line numberDiff line change
@@ -26,92 +26,6 @@ rust_win32_rand_gen
2626
rust_win32_rand_release
2727
upcall_rust_personality
2828
upcall_reset_stack_limit
29-
rust_uv_loop_new
30-
rust_uv_loop_delete
31-
rust_uv_walk
32-
rust_uv_loop_set_data
33-
rust_uv_run
34-
rust_uv_close
35-
rust_uv_async_send
36-
rust_uv_async_init
37-
rust_uv_timer_init
38-
rust_uv_timer_start
39-
rust_uv_timer_stop
40-
rust_uv_tcp_init
41-
rust_uv_buf_init
42-
rust_uv_strerror
43-
rust_uv_err_name
44-
rust_uv_ip4_addr
45-
rust_uv_ip4_name
46-
rust_uv_ip6_addr
47-
rust_uv_ip6_name
48-
rust_uv_tcp_connect
49-
rust_uv_tcp_bind
50-
rust_uv_tcp_connect6
51-
rust_uv_tcp_bind6
52-
rust_uv_tcp_getsockname
53-
rust_uv_tcp_nodelay
54-
rust_uv_tcp_keepalive
55-
rust_uv_tcp_simultaneous_accepts
56-
rust_uv_udp_init
57-
rust_uv_udp_bind
58-
rust_uv_udp_bind6
59-
rust_uv_udp_send
60-
rust_uv_udp_send6
61-
rust_uv_udp_recv_start
62-
rust_uv_udp_recv_stop
63-
rust_uv_get_udp_handle_from_send_req
64-
rust_uv_udp_getsockname
65-
rust_uv_udp_set_membership
66-
rust_uv_udp_set_multicast_loop
67-
rust_uv_udp_set_multicast_ttl
68-
rust_uv_udp_set_ttl
69-
rust_uv_udp_set_broadcast
70-
rust_uv_is_ipv4_sockaddr
71-
rust_uv_is_ipv6_sockaddr
72-
rust_uv_malloc_sockaddr_storage
73-
rust_uv_free_sockaddr_storage
74-
rust_uv_listen
75-
rust_uv_accept
76-
rust_uv_write
77-
rust_uv_read_start
78-
rust_uv_read_stop
79-
rust_uv_is_ipv4_addrinfo
80-
rust_uv_is_ipv6_addrinfo
81-
rust_uv_get_next_addrinfo
82-
rust_uv_addrinfo_as_sockaddr_in
83-
rust_uv_addrinfo_as_sockaddr_in6
84-
rust_uv_get_stream_handle_from_connect_req
85-
rust_uv_get_stream_handle_from_write_req
86-
rust_uv_get_loop_for_uv_handle
87-
rust_uv_get_data_for_uv_loop
88-
rust_uv_set_data_for_uv_loop
89-
rust_uv_get_data_for_uv_handle
90-
rust_uv_set_data_for_uv_handle
91-
rust_uv_get_data_for_req
92-
rust_uv_set_data_for_req
93-
rust_uv_get_base_from_buf
94-
rust_uv_get_len_from_buf
95-
rust_uv_getaddrinfo
96-
rust_uv_freeaddrinfo
97-
rust_uv_idle_init
98-
rust_uv_idle_start
99-
rust_uv_idle_stop
100-
rust_uv_fs_open
101-
rust_uv_fs_unlink
102-
rust_uv_fs_write
103-
rust_uv_fs_read
104-
rust_uv_fs_close
105-
rust_uv_get_result_from_fs_req
106-
rust_uv_get_ptr_from_fs_req
107-
rust_uv_get_loop_from_fs_req
108-
rust_uv_fs_stat
109-
rust_uv_fs_fstat
110-
rust_uv_fs_req_cleanup
111-
rust_uv_populate_uv_stat
112-
rust_uv_fs_mkdir
113-
rust_uv_fs_rmdir
114-
rust_uv_fs_readdir
11529
rust_dbg_lock_create
11630
rust_dbg_lock_destroy
11731
rust_dbg_lock_lock
@@ -128,9 +42,6 @@ rust_signal_little_lock
12842
rust_wait_little_lock
12943
tdefl_compress_mem_to_heap
13044
tinfl_decompress_mem_to_heap
131-
rust_uv_ip4_port
132-
rust_uv_ip6_port
133-
rust_uv_tcp_getpeername
13445
rust_raw_thread_start
13546
rust_raw_thread_join
13647
rust_raw_thread_delete
@@ -150,14 +61,6 @@ rust_dbg_extern_return_TwoU32s
15061
rust_dbg_extern_return_TwoU64s
15162
rust_dbg_extern_identity_double
15263
rust_dbg_extern_identity_u8
153-
rust_uv_handle_size
154-
rust_uv_req_size
155-
rust_uv_handle_type_max
156-
rust_uv_req_type_max
157-
rust_uv_ip4_addrp
158-
rust_uv_ip6_addrp
159-
rust_uv_free_ip4_addr
160-
rust_uv_free_ip6_addr
16164
rust_initialize_rt_tls_key
16265
rust_dbg_next_port
16366
rust_try
@@ -172,23 +75,5 @@ rust_get_global_args_ptr
17275
rust_take_global_args_lock
17376
rust_drop_global_args_lock
17477
rust_get_test_int
175-
rust_uv_get_loop_from_getaddrinfo_req
176-
rust_uv_spawn
177-
rust_uv_process_kill
178-
rust_set_stdio_container_flags
179-
rust_set_stdio_container_fd
180-
rust_set_stdio_container_stream
181-
rust_uv_process_pid
182-
rust_uv_pipe_init
183-
rust_uv_signal_init
184-
rust_uv_signal_start
185-
rust_uv_signal_stop
18678
rust_take_dlerror_lock
18779
rust_drop_dlerror_lock
188-
rust_uv_pipe_open
189-
rust_uv_pipe_bind
190-
rust_uv_pipe_connect
191-
rust_uv_tty_init
192-
rust_uv_tty_set_mode
193-
rust_uv_tty_get_winsize
194-
rust_uv_guess_handle

0 commit comments

Comments
 (0)