-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Droping rebory and migrate to cmake-js (#14)
- Migrate to cmake-js - Fix and pretty userspace in go binding - fix typescript code Reviewed-on: https://sirherobrine23.org/Wireguard/Wireguard-tools.js/pulls/14 Co-authored-by: Matheus Sampaio Queiroga <[email protected]> Co-committed-by: Matheus Sampaio Queiroga <[email protected]>
- Loading branch information
1 parent
b26f59e
commit 5282a0c
Showing
26 changed files
with
565 additions
and
847 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Folder-specific settings | ||
// | ||
// For a full list of overridable settings, and general information on folder-specific settings, | ||
// see the documentation: https://zed.dev/docs/configuring-zed#folder-specific-settings | ||
{ | ||
"remove_trailing_whitespace_on_save": true, | ||
"ensure_final_newline_on_save": true, | ||
"formatter": "auto", | ||
"format_on_save": "off", | ||
"tab_size": 2, | ||
"languages": { | ||
"TypeScript": { | ||
"hard_tabs": false | ||
"format_on_save": true, | ||
"code_actions_on_format": { | ||
"source.organizeImports": true, | ||
"source.removeUnusedImports": true | ||
} | ||
}, | ||
"JavaScript": { | ||
"hard_tabs": false | ||
"format_on_save": true, | ||
"code_actions_on_format": { | ||
"source.organizeImports": true, | ||
"source.removeUnusedImports": true | ||
} | ||
}, | ||
"Go": { | ||
"format_on_save": true | ||
}, | ||
"C++": { | ||
"hard_tabs": false | ||
}, | ||
"C": { | ||
"hard_tabs": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
cmake_policy(SET CMP0091 NEW) | ||
cmake_policy(SET CMP0042 NEW) | ||
|
||
project (wg) | ||
|
||
add_compile_definitions(NAPI_VERSION=8 NAPI_CPP_EXCEPTIONS) | ||
# set_target_properties(PROPERTIES CXX_STANDARD 17) | ||
# set_target_properties(PROPERTIES C_STANDARD 17) | ||
set(CMAKE_C_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
include_directories(${CMAKE_JS_INC}) | ||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/addon") | ||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/addon/genKey") | ||
# Include N-API wrappers | ||
# $ node -p "require('node-addon-api').include" | ||
# "/home/will/projects/financialcpp/financialcpp/node_modules/node-addon-api" | ||
execute_process(COMMAND node -p "require('node-addon-api').include" | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
OUTPUT_VARIABLE NODE_ADDON_API_DIR | ||
) | ||
|
||
# strip `"` and `\n` from the output above | ||
string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) | ||
string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) | ||
|
||
include_directories(PRIVATE ${NODE_ADDON_API_DIR}) | ||
|
||
if(UNIX) | ||
add_definitions(-fpermissive -fexceptions -w -fpermissive -fPIC) | ||
endif() | ||
|
||
file(GLOB GSOURCE_FILES | ||
"${CMAKE_CURRENT_SOURCE_DIR}/addon/main.cpp" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/addon/genKey/wgkeys.cpp" | ||
) | ||
|
||
if(MSVC) | ||
file(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/addon/win/wginterface.cpp") | ||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/addon/win") | ||
add_compile_definitions(_HAS_EXCEPTIONS=1 ONSTARTADDON) | ||
target_link_libraries(${PROJECT_NAME} | ||
"wbemuuid.lib" | ||
"bcrypt.lib" | ||
"crypt32.lib" | ||
"iphlpapi.lib" | ||
"kernel32.lib" | ||
"ntdll.lib" | ||
"ws2_32.lib" | ||
"setupapi.lib" | ||
) | ||
elseif(UNIX AND NOT APPLE OR ANDROID) | ||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/addon/linux") | ||
file(GLOB SOURCE_FILES | ||
"${CMAKE_CURRENT_SOURCE_DIR}/addon/linux/wireguard.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/addon/linux/wginterface.cpp" | ||
) | ||
else() | ||
message(STATUS "Buiding go Userspace") | ||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/addon/userspace/wg-go.o) | ||
file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/addon/userspace/wg-go.o) | ||
endif() | ||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/addon/userspace/wg-go.h) | ||
file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/addon/userspace/wg-go.h) | ||
endif() | ||
set(ENV{CGO_ENABLED} 1) | ||
set(ENV{LDFLAGS} -w) | ||
# Remove CXX and CC envs to CGO | ||
set(ENV{DCXX} ENV{CXX}) | ||
set(ENV{DCC} ENV{CC}) | ||
set(ENV{CXX}) | ||
set(ENV{CC}) | ||
execute_process( | ||
COMMAND go build -trimpath -v -o ../wg-go.o -buildmode c-archive . | ||
# COMMAND env | ||
RESULT_VARIABLE GOCODE | ||
OUTPUT_VARIABLE GOBUILDLOG | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/addon/userspace/go | ||
) | ||
set(ENV{CXX} ENV{DCXX}) | ||
set(ENV{CC} ENV{DCC}) | ||
if(NOT GOCODE EQUAL "0") | ||
message(FATAL_ERROR "cannot build go userspace code exit ${GOCODE}\n${GOBUILDLOG}") | ||
endif() | ||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/addon/userspace") | ||
set(USERSPACEOBJ ${CMAKE_CURRENT_SOURCE_DIR}/addon/userspace/wg-go.o) | ||
file(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/addon/userspace/wginterface.cpp") | ||
endif() | ||
|
||
add_library(${PROJECT_NAME} SHARED ${GSOURCE_FILES} ${SOURCE_FILES} ${CMAKE_JS_SRC}) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node") | ||
target_link_libraries(${PROJECT_NAME} ${USERSPACEOBJ} ${CMAKE_JS_LIB}) | ||
|
||
if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET) | ||
# Generate node.lib | ||
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS}) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.