Skip to content

Commit 306f8b1

Browse files
committed
WR macos app bundle
1 parent fee9a42 commit 306f8b1

File tree

5 files changed

+125
-47
lines changed

5 files changed

+125
-47
lines changed

configure.ac

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,11 @@ AC_ARG_ENABLE([ns-self-contained],
566566
[EN_NS_SELF_CONTAINED=$enableval],
567567
[EN_NS_SELF_CONTAINED=yes])
568568

569+
AC_ARG_ENABLE(wr-self-contained,
570+
[AS_HELP_STRING([--enable-wr-self-contained],
571+
[enable self contained Webrender build under macOS])],
572+
EN_NS_SELF_CONTAINED=$enableval)
573+
569574
locallisppathset=no
570575
AC_ARG_ENABLE([locallisppath],
571576
[AS_HELP_STRING([--enable-locallisppath=PATH],
@@ -1965,6 +1970,42 @@ if test "${with_pgtk}" = "yes"; then
19651970
window_system=pgtk
19661971
fi
19671972

1973+
1974+
HAVE_WR=no
1975+
HAVE_WR_NS=no
1976+
if test "${with_wr}" = "yes"; then
1977+
with_x=no
1978+
with_ns=no
1979+
1980+
if test "${window_system}" = "none"; then
1981+
window_system=wr
1982+
else
1983+
AS_VAR_APPEND([alternative_window_systems], [wr])
1984+
fi
1985+
HAVE_WR=yes
1986+
1987+
case $opsys in
1988+
cygwin|mingw32) ;;
1989+
darwin) HAVE_WR_NS=yes ;;
1990+
*) ;;
1991+
esac
1992+
1993+
AC_DEFINE(HAVE_WR, 1,
1994+
[Define to 1 if you want to use the webrender.])
1995+
1996+
fi
1997+
AC_SUBST([HAVE_WR])
1998+
AC_SUBST([HAVE_WR_NS])
1999+
2000+
if test "${HAVE_WR_NS}" = yes; then
2001+
ns_appdir=`pwd`/nextstep/Emacs.app
2002+
ns_appbindir=${ns_appdir}/Contents/MacOS
2003+
ns_applibexecdir=${ns_appdir}/Contents/MacOS/libexec
2004+
ns_applibdir=${ns_appdir}/Contents/Frameworks
2005+
ns_appresdir=${ns_appdir}/Contents/Resources
2006+
ns_appsrc=Cocoa/Emacs.base
2007+
fi
2008+
19682009
AC_PATH_X
19692010
if test "$no_x" != yes && test "${with_pgtk}" != "yes"; then
19702011
window_system=x11
@@ -2171,6 +2212,10 @@ if test "${HAVE_NS}" = yes; then
21712212
fi
21722213

21732214
window_system=nextstep
2215+
NS_OBJC_OBJ="nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o $ns_fontfile"
2216+
fi
2217+
2218+
if test "${HAVE_NS}" = yes || test "${HAVE_WR_NS}" = yes; then
21742219
# set up packaging dirs
21752220
if test "${EN_NS_SELF_CONTAINED}" = yes; then
21762221
AC_DEFINE([NS_SELF_CONTAINED], [1], [Build an NS bundled app])
@@ -2191,8 +2236,6 @@ if test "${HAVE_NS}" = yes; then
21912236
test "$locallisppathset" = no && locallisppath="\${ns_appresdir}/site-lisp"
21922237
INSTALL_ARCH_INDEP_EXTRA=
21932238
fi
2194-
2195-
NS_OBJC_OBJ="nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o $ns_fontfile"
21962239
fi
21972240
CFLAGS="$tmp_CFLAGS"
21982241
CPPFLAGS="$tmp_CPPFLAGS"
@@ -2404,19 +2447,6 @@ AC_SUBST([HAIKU_OBJ])
24042447
AC_SUBST([HAIKU_CXX_OBJ])
24052448
AC_SUBST([HAIKU_CFLAGS])
24062449

2407-
HAVE_WR=no
2408-
if test "${with_wr}" = "yes"; then
2409-
if test "${window_system}" = "none"; then
2410-
window_system=wr
2411-
else
2412-
AS_VAR_APPEND([alternative_window_systems], [wr])
2413-
fi
2414-
HAVE_WR=yes
2415-
AC_DEFINE(HAVE_WR, 1,
2416-
[Define to 1 if you want to use the webrender.])
2417-
fi
2418-
AC_SUBST([HAVE_WR])
2419-
24202450
## $window_system is now set to the window system we will
24212451
## ultimately use.
24222452

@@ -6850,7 +6880,7 @@ fi
68506880

68516881
echo
68526882

6853-
if test "$HAVE_NS" = "yes"; then
6883+
if test "$HAVE_NS" = "yes" || test "$HAVE_WR_NS" = "yes"; then
68546884
echo
68556885
AS_ECHO(["Run '${MAKE-make}' to build Emacs, then run 'src/emacs' to test it.
68566886
Run '${MAKE-make} install' in order to build an application bundle.
@@ -6954,13 +6984,14 @@ dnl the use of force in the 'epaths-force' rule in Makefile.in.
69546984
AC_CONFIG_COMMANDS([src/epaths.h], [
69556985
if test "${opsys}" = "mingw32"; then
69566986
${MAKE-make} MAKEFILE_NAME=do-not-make-Makefile epaths-force-w32
6957-
elif test "$HAVE_NS" = "yes" && test "$EN_NS_SELF_CONTAINED" = "yes"; then
6987+
elif (test "$HAVE_NS" = "yes" || test "$HAVE_WR_NS" = "yes") && \
6988+
test "$EN_NS_SELF_CONTAINED" = "yes"; then
69586989
${MAKE-make} MAKEFILE_NAME=do-not-make-Makefile epaths-force-ns-self-contained
69596990
else
69606991
${MAKE-make} MAKEFILE_NAME=do-not-make-Makefile epaths-force
69616992
fi || AC_MSG_ERROR(['src/epaths.h' could not be made.])
69626993
], [GCC="$GCC" CPPFLAGS="$CPPFLAGS" opsys="$opsys" HAVE_NS="$HAVE_NS"
6963-
EN_NS_SELF_CONTAINED="$EN_NS_SELF_CONTAINED"])
6994+
HAVE_WR_NS="$HAVE_WR_NS" EN_NS_SELF_CONTAINED="$EN_NS_SELF_CONTAINED"])
69646995

69656996
dnl NB we have to cheat and use the ac_... version because abs_top_srcdir
69666997
dnl is not yet set, sigh. Or we could use ../$srcdir/src/.gdbinit,

src/emacs.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,12 @@ load_pdump (int argc, char **argv)
953953
/* On MS-Windows, PATH_EXEC normally starts with a literal
954954
"%emacs_dir%", so it will never work without some tweaking. */
955955
path_exec = w32_relocate (path_exec);
956-
#elif defined (HAVE_NS)
956+
#elif defined (NS_SELF_CONTAINED)
957+
#ifdef HAVE_NS
957958
path_exec = ns_relocate (path_exec);
959+
#elif defined (HAVE_WR)
960+
path_exec = app_bundle_relocate (path_exec);
961+
#endif
958962
#endif
959963

960964
/* Look for "emacs-FINGERPRINT.pdmp" in PATH_EXEC. We hardcode
@@ -3219,8 +3223,10 @@ decode_env_path (const char *evarname, const char *defalt, bool empty)
32193223
{
32203224
const char *path, *p;
32213225
Lisp_Object lpath, element, tem;
3226+
#ifdef HAVE_NS
32223227
#ifdef NS_SELF_CONTAINED
32233228
void *autorelease = NULL;
3229+
#endif
32243230
#endif
32253231
/* Default is to use "." for empty path elements.
32263232
But if argument EMPTY is true, use nil instead. */
@@ -3249,9 +3255,14 @@ decode_env_path (const char *evarname, const char *defalt, bool empty)
32493255
if (!path)
32503256
{
32513257
#ifdef NS_SELF_CONTAINED
3258+
#ifdef HAVE_NS
32523259
/* ns_relocate needs a valid autorelease pool around it. */
32533260
autorelease = ns_alloc_autorelease_pool ();
32543261
path = ns_relocate (defalt);
3262+
#elif defined (HAVE_WR)
3263+
path = app_bundle_relocate (defalt);
3264+
#endif
3265+
32553266
#else
32563267
path = defalt;
32573268
#endif
@@ -3353,10 +3364,11 @@ decode_env_path (const char *evarname, const char *defalt, bool empty)
33533364
else
33543365
break;
33553366
}
3356-
3367+
#ifdef HAVE_NS
33573368
#ifdef NS_SELF_CONTAINED
33583369
if (autorelease)
33593370
ns_release_autorelease_pool (autorelease);
3371+
#endif
33603372
#endif
33613373
return Fnreverse (lpath);
33623374
}

src/wr/src/lib.rs

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,47 +28,54 @@ mod texture;
2828
mod util;
2929
mod wrterm;
3030

31+
mod platform {
32+
pub mod macos;
33+
}
34+
35+
#[cfg(target_os = "macos")]
36+
pub use crate::platform::macos;
37+
3138
pub use crate::wrterm::{tip_frame, wr_display_list};
3239

3340
pub use crate::event_loop::wr_select;
34-
pub use crate::wrterm::wr_get_fontset;
35-
pub use crate::wrterm::wr_get_font;
36-
pub use crate::wrterm::wr_get_window_desc;
37-
pub use crate::wrterm::wr_get_display_info;
38-
pub use crate::wrterm::wr_get_display;
41+
pub use crate::wrterm::check_x_display_info;
42+
pub use crate::wrterm::frame_set_mouse_pixel_position;
43+
pub use crate::wrterm::get_keysym_name;
44+
pub use crate::wrterm::image_pixmap_draw_cross;
45+
pub use crate::wrterm::image_sync_to_pixmaps;
46+
pub use crate::wrterm::wr_can_use_native_image_api;
3947
pub use crate::wrterm::wr_get_baseline_offset;
48+
pub use crate::wrterm::wr_get_display;
49+
pub use crate::wrterm::wr_get_display_info;
50+
pub use crate::wrterm::wr_get_font;
51+
pub use crate::wrterm::wr_get_fontset;
4052
pub use crate::wrterm::wr_get_pixel;
41-
pub use crate::wrterm::wr_put_pixel;
42-
pub use crate::wrterm::wr_can_use_native_image_api;
53+
pub use crate::wrterm::wr_get_window_desc;
4354
pub use crate::wrterm::wr_load_image;
55+
pub use crate::wrterm::wr_put_pixel;
4456
pub use crate::wrterm::wr_transform_image;
45-
pub use crate::wrterm::get_keysym_name;
46-
pub use crate::wrterm::check_x_display_info;
47-
pub use crate::wrterm::frame_set_mouse_pixel_position;
48-
pub use crate::wrterm::image_sync_to_pixmaps;
49-
pub use crate::wrterm::image_pixmap_draw_cross;
50-
pub use crate::wrterm::Fx_hide_tip;
57+
pub use crate::wrterm::Fwr_api_capture;
58+
pub use crate::wrterm::Fwr_api_stop_capture_sequence;
5159
pub use crate::wrterm::Fwr_create_frame;
52-
pub use crate::wrterm::Fx_open_connection;
53-
pub use crate::wrterm::Fxw_display_color_p;
54-
pub use crate::wrterm::Fx_display_grayscale_p;
55-
pub use crate::wrterm::Fxw_color_values;
56-
pub use crate::wrterm::Fx_register_dnd_atom;
5760
pub use crate::wrterm::Fx_change_window_property;
5861
pub use crate::wrterm::Fx_display_color_cells;
59-
pub use crate::wrterm::Fx_display_planes;
60-
pub use crate::wrterm::Fx_wm_set_size_hint;
61-
pub use crate::wrterm::Fx_display_visual_class;
62+
pub use crate::wrterm::Fx_display_grayscale_p;
6263
pub use crate::wrterm::Fx_display_monitor_attributes_list;
63-
pub use crate::wrterm::Fx_display_pixel_width;
6464
pub use crate::wrterm::Fx_display_pixel_height;
65-
pub use crate::wrterm::Fx_own_selection_internal;
65+
pub use crate::wrterm::Fx_display_pixel_width;
66+
pub use crate::wrterm::Fx_display_planes;
67+
pub use crate::wrterm::Fx_display_visual_class;
68+
pub use crate::wrterm::Fx_frame_edges;
6669
pub use crate::wrterm::Fx_get_selection_internal;
67-
pub use crate::wrterm::Fx_selection_owner_p;
70+
pub use crate::wrterm::Fx_hide_tip;
71+
pub use crate::wrterm::Fx_open_connection;
72+
pub use crate::wrterm::Fx_own_selection_internal;
73+
pub use crate::wrterm::Fx_register_dnd_atom;
6874
pub use crate::wrterm::Fx_selection_exists_p;
69-
pub use crate::wrterm::Fx_frame_edges;
70-
pub use crate::wrterm::Fwr_api_capture;
71-
pub use crate::wrterm::Fwr_api_stop_capture_sequence;
75+
pub use crate::wrterm::Fx_selection_owner_p;
76+
pub use crate::wrterm::Fx_wm_set_size_hint;
77+
pub use crate::wrterm::Fxw_color_values;
78+
pub use crate::wrterm::Fxw_display_color_p;
7279

7380
// #[no_mangle]
7481
// pub extern "C" fn syms_of_ftfont() {

src/wr/src/platform/macos.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use std::ffi::CStr;
2+
use std::ffi::CString;
3+
4+
use core_foundation::bundle::CFBundle;
5+
6+
/// This function acts.
7+
#[no_mangle]
8+
#[allow(unused_doc_comments)]
9+
pub extern "C" fn app_bundle_relocate(epath: *const ::libc::c_char) -> *const ::libc::c_char {
10+
let main_bundle = CFBundle::main_bundle();
11+
match main_bundle.path() {
12+
Some(path) => {
13+
let relocated_path: &CStr = unsafe { CStr::from_ptr(epath) };
14+
let relocated_path: &str = relocated_path.to_str().unwrap();
15+
16+
if !std::path::Path::new(relocated_path).is_absolute() {
17+
let relocated_path = path.join(relocated_path).as_path().display().to_string();
18+
let relocated_path = CString::new(relocated_path).unwrap();
19+
relocated_path.into_raw()
20+
} else {
21+
epath
22+
}
23+
}
24+
None => epath,
25+
}
26+
}

src/wrterm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ extern int wr_select (int nfds, fd_set *readfds, fd_set *writefds,
169169
#define BLACK_PIX_DEFAULT(f) 0
170170
#define WHITE_PIX_DEFAULT(f) 65535
171171

172+
extern const char *app_bundle_relocate (const char *);
173+
172174
/* Symbol initializations implemented in each pgtk sources. */
173175
extern void syms_of_wrterm(void);
174176
extern void syms_of_wrterm_rust(void);

0 commit comments

Comments
 (0)