build gui and assemble app bundles into one singular app bundle

This commit is contained in:
jeff 2022-07-25 11:23:05 -04:00 committed by Jason Rhinelander
parent 279b5710cc
commit b8896740de
6 changed files with 88 additions and 57 deletions

View File

@ -25,7 +25,7 @@ cmake \
-DCMAKE_BUILD_TYPE=Release \
"$@" \
..
ninja sign
ninja sign -j1
echo -e "Build complete, your app is here:\n"
ls -lad $(pwd)/Lokinet.app

View File

@ -9,7 +9,7 @@
<string>Lokinet</string>
<key>CFBundleExecutable</key>
<string>Lokinet</string>
<string>lokinet-gui</string>
<key>CFBundleIdentifier</key>
<string>org.lokinet</string>

View File

@ -1,4 +1,3 @@
set(exetargets lokinet)
if(APPLE)
@ -56,7 +55,6 @@ foreach(exe ${exetargets})
endif()
target_link_libraries(${exe} PUBLIC liblokinet)
target_include_directories(${exe} PUBLIC "${PROJECT_SOURCE_DIR}")
add_log_tag(${exe})
if(should_install)
if(APPLE)
install(TARGETS ${exe}
@ -69,6 +67,36 @@ foreach(exe ${exetargets})
endif()
endforeach()
set(default_with_gui OFF)
if(APPLE)
set(default_with_gui ON)
endif()
option(WITH_GUI "build electron gui from source" ${default_with_gui})
if (WITH_GUI)
find_program(YARN yarn REQUIRED)
message(STATUS "Found yarn: ${YARN}")
if(NOT GUI_GIT_REPO)
set(GUI_GIT_REPO "https://github.com/oxen-io/lokinet-gui")
endif()
if(NOT GUI_GIT_BRANCH)
set(GUI_GIT_BRANCH "stable")
endif()
if(NOT YARN_TARGET)
set(YARN_TARGET pack:raw)
if(APPLE)
set(YARN_TARGET macos:raw)
endif()
endif()
message(STATUS "will build gui: ${GUI_GIT_REPO} (branch: ${GUI_GIT_BRANCH}) using ${YARN} ${YARN_TARGET}")
add_custom_target(lokinet-gui
COMMAND rm -rf "${PROJECT_BINARY_DIR}/lokinet-gui" && git clone "${GUI_GIT_REPO}" -b ${GUI_GIT_BRANCH} "${PROJECT_BINARY_DIR}/lokinet-gui" && cd "${PROJECT_BINARY_DIR}/lokinet-gui" && ${YARN} install --frozen-lockfile && ${YARN} ${YARN_TARGET})
else()
message(STATUS "not building gui")
add_custom_target(lokinet-gui COMMAND "true")
endif()
if(APPLE)
option(MACOS_SYSTEM_EXTENSION
"Build the network extension as a system extension rather than a plugin. This must be ON for non-app store release builds, and must be OFF for dev builds and Mac App Store distribution builds"
@ -154,18 +182,9 @@ if(APPLE)
$<TARGET_BUNDLE_DIR:lokinet>/Contents/embedded.provisionprofile)
endif()
add_custom_command(TARGET lokinet
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/contrib/bootstrap/mainnet.signed
$<TARGET_BUNDLE_DIR:lokinet-extension>/Contents/Resources/bootstrap.signed
COMMAND mkdir -p $<TARGET_BUNDLE_DIR:lokinet>/${lokinet_ext_dir}
COMMAND cp -a $<TARGET_BUNDLE_DIR:lokinet-extension> $<TARGET_BUNDLE_DIR:lokinet>/${lokinet_ext_dir}
${post_build_pp}
)
set_target_properties(lokinet
PROPERTIES
OUTPUT_NAME Lokinet
OUTPUT_NAME Lokinet
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_STRING "Lokinet IP Packet Onion Router"
MACOSX_BUNDLE_BUNDLE_NAME "Lokinet"
@ -178,15 +197,29 @@ if(APPLE)
MACOSX_BUNDLE_COPYRIGHT "© 2022, The Oxen Project"
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}"
)
set(copy_gui)
if(BUILD_GUI)
set(copy_gui COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_BINARY_DIR}/lokinet-gui/release/mac/lokinet-gui.app $<TARGET_BUNDLE_DIR:lokinet>)
endif()
add_custom_target(assemble
DEPENDS lokinet lokinet-extension lokinet-gui
${copy_gui}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/contrib/bootstrap/mainnet.signed
$<TARGET_BUNDLE_DIR:lokinet-extension>/Contents/Resources/bootstrap.signed
COMMAND mkdir -p $<TARGET_BUNDLE_DIR:lokinet>/${lokinet_ext_dir}
COMMAND cp -a $<TARGET_BUNDLE_DIR:lokinet-extension> $<TARGET_BUNDLE_DIR:lokinet>/${lokinet_ext_dir}
${post_build_pp})
if(NOT CODESIGN)
message(STATUS "codesigning disabled")
add_custom_target(
sign
DEPENDS lokinet lokinet-extension
DEPENDS assemble
COMMAND "true")
elseif(CODESIGN)
set(SIGN_TARGET "${PROJECT_BINARY_DIR}/lokinet.app")
set(SIGN_TARGET "${PROJECT_BINARY_DIR}/Lokinet.app")
if(MACOS_SYSTEM_EXTENSION)
set(LOKINET_ENTITLEMENTS_TYPE sysext)
else()
@ -198,7 +231,7 @@ if(APPLE)
@ONLY)
add_custom_target(
sign
DEPENDS "${PROJECT_BINARY_DIR}/sign.sh" lokinet lokinet-extension
DEPENDS "${PROJECT_BINARY_DIR}/sign.sh" assemble
COMMAND "${PROJECT_BINARY_DIR}/sign.sh"
)

View File

@ -16,14 +16,13 @@ class LokinetMain: NSObject, NSApplicationDelegate {
let netextBundleId = "org.lokinet.network-extension"
func applicationDidFinishLaunching(_: Notification) {
if self.mode == START {
if mode == START {
startNetworkExtension()
} else if self.mode == STOP {
} else if mode == STOP {
tearDownVPNTunnel()
} else {
self.result(msg: HELP_STRING)
result(msg: HELP_STRING)
}
}
func bail() {
@ -33,7 +32,7 @@ class LokinetMain: NSObject, NSApplicationDelegate {
func result(msg: String) {
NSLog(msg)
// TODO: does lokinet continue after this?
self.bail()
bail()
}
func tearDownVPNTunnel() {
@ -58,19 +57,18 @@ class LokinetMain: NSObject, NSApplicationDelegate {
}
func startNetworkExtension() {
#if MACOS_SYSTEM_EXTENSION
NSLog("Loading Lokinet network extension")
// Start by activating the system extension
let activationRequest = OSSystemExtensionRequest.activationRequest(forExtensionWithIdentifier: netextBundleId, queue: .main)
activationRequest.delegate = self
OSSystemExtensionManager.shared.submitRequest(activationRequest)
#else
setupVPNTunnel()
#endif
#if MACOS_SYSTEM_EXTENSION
NSLog("Loading Lokinet network extension")
// Start by activating the system extension
let activationRequest = OSSystemExtensionRequest.activationRequest(forExtensionWithIdentifier: netextBundleId, queue: .main)
activationRequest.delegate = self
OSSystemExtensionManager.shared.submitRequest(activationRequest)
#else
setupVPNTunnel()
#endif
}
func setupVPNTunnel() {
NSLog("Starting up Lokinet tunnel")
NETunnelProviderManager.loadAllFromPreferences { [self] (savedManagers: [NETunnelProviderManager]?, error: Error?) in
if let error = error {
@ -113,7 +111,7 @@ class LokinetMain: NSObject, NSApplicationDelegate {
self.initializeConnectionObserver()
try self.vpnManager.connection.startVPNTunnel()
} catch let error as NSError {
self.result(msg: error.localizedDescription)
self.result(msg: error.localizedDescription)
} catch {
self.result(msg: "There was a fatal error")
}
@ -145,32 +143,32 @@ class LokinetMain: NSObject, NSApplicationDelegate {
#if MACOS_SYSTEM_EXTENSION
extension LokinetMain: OSSystemExtensionRequestDelegate {
func request(_ request: OSSystemExtensionRequest, didFinishWithResult result: OSSystemExtensionRequest.Result) {
guard result == .completed else {
NSLog("Unexpected result %d for system extension request", result.rawValue)
return
extension LokinetMain: OSSystemExtensionRequestDelegate {
func request(_: OSSystemExtensionRequest, didFinishWithResult result: OSSystemExtensionRequest.Result) {
guard result == .completed else {
NSLog("Unexpected result %d for system extension request", result.rawValue)
return
}
NSLog("Lokinet system extension loaded")
setupVPNTunnel()
}
NSLog("Lokinet system extension loaded")
setupVPNTunnel()
}
func request(_ request: OSSystemExtensionRequest, didFailWithError error: Error) {
NSLog("System extension request failed: %@", error.localizedDescription)
}
func request(_: OSSystemExtensionRequest, didFailWithError error: Error) {
NSLog("System extension request failed: %@", error.localizedDescription)
}
func requestNeedsUserApproval(_ request: OSSystemExtensionRequest) {
NSLog("Extension %@ requires user approval", request.identifier)
}
func requestNeedsUserApproval(_ request: OSSystemExtensionRequest) {
NSLog("Extension %@ requires user approval", request.identifier)
}
func request(_ request: OSSystemExtensionRequest,
actionForReplacingExtension existing: OSSystemExtensionProperties,
withExtension extension: OSSystemExtensionProperties) -> OSSystemExtensionRequest.ReplacementAction {
NSLog("Replacing extension %@ version %@ with version %@", request.identifier, existing.bundleShortVersion, `extension`.bundleShortVersion)
return .replace
func request(_ request: OSSystemExtensionRequest,
actionForReplacingExtension existing: OSSystemExtensionProperties,
withExtension extension: OSSystemExtensionProperties) -> OSSystemExtensionRequest.ReplacementAction
{
NSLog("Replacing extension %@ version %@ with version %@", request.identifier, existing.bundleShortVersion, `extension`.bundleShortVersion)
return .replace
}
}
}
#endif

View File

@ -213,7 +213,7 @@ static void del_default_route(void* ctx) {
NSString* dns_ip = [NSString stringWithUTF8String:conf.dns_bind_ip];
#else
// TODO: placeholder
NSString* dns_ip = @"127.0.0.1";
NSString* dns_ip = ip;
#endif
NSLog(@"setting dns to %@", dns_ip);
NEDNSSettings* dns = [[NEDNSSettings alloc] initWithServers:@[dns_ip]];

View File

@ -93,9 +93,9 @@ build 1 or many cross targets:
### MacOS <span id="mac-install" />
Lokinet ~~is~~ will be available on the Apple App store.
Source code compilation of Lokinet by end users is not supported or permitted by apple on their platforms, see [this](contrib/macos/README.txt) for more information.
Source code compilation of Lokinet by end users is not supported or permitted by apple on their platforms, see [this](contrib/macos/README.txt) for more information. If you find this disagreeable consider using a platform that permits compiling from source.
If you find this disagreeable consider using a platform that permits compiling from source.
### Windows <span id="windows-install" />