Skip to content

Commit

Permalink
Windows Support (#36)
Browse files Browse the repository at this point in the history
Fist commit to add Windows support to create Wireguard interfaces and Manager configs

Signed-off-by: Matheus Sampaio Queiroga <[email protected]>
  • Loading branch information
Sirherobrine23 authored Sep 11, 2023
1 parent 6b94b90 commit 1ed4fca
Show file tree
Hide file tree
Showing 23 changed files with 1,516 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Publish
on:
release:
types:
Expand Down
109 changes: 69 additions & 40 deletions .github/workflows/testProject.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ on:
- main

jobs:
test:
linux_test:
runs-on: ubuntu-latest
strategy:
matrix:
node_version: [ 16.x, 17.x, 18.x, 19.x ]
os: [ ubuntu, macos ]
runs-on: ${{ matrix.os }}-latest
name: "Test on ${{ matrix.os }} with Node ${{ matrix.node_version }}"
steps:
- uses: actions/checkout@v4
name: Checkout
Expand All @@ -26,15 +24,45 @@ jobs:

- name: Install dependencies
run: |
npm install --no-save
sudo npm install -g ts-node typescript mocha
export DEBIAN_FRONTEND=noninteractive
sudo apt update
sudo apt install -y binutils-multiarch gcc-*aarch64-linux-gnu gcc-*aarch64-linux-gnu-base g++-*aarch64-linux-gnu libc6-arm64-cross
npm install --no-save --ignore-scripts
- name: Test
run: npm run prebuildify -- -v && sudo -E ./node_modules/.bin/mocha ./src

- name: Upload generate interface
uses: actions/upload-artifact@v3
with:
name: addrs_${{ runner.os }}_${{ matrix.node_version }}
path: "*.addrs.json"

- name: Upload generate interface
uses: actions/upload-artifact@v3
with:
retention-days: 7
name: prebuilds_${{ runner.os }}
path: "prebuilds/**"

macos_test:
runs-on: macos-latest
strategy:
matrix:
node_version: [ 16.x, 17.x, 18.x, 19.x ]
steps:
- uses: actions/checkout@v4
name: Checkout

- uses: actions/setup-node@v3
name: Setup Node.js
with:
node-version: ${{ matrix.node_version }}

- name: Setup Go environment
if: matrix.os == 'macos'
uses: actions/[email protected]

- name: "Start wireguard interface (MacOS)"
if: matrix.os == 'macos'
- name: Setup wireguard-go
run: |
cd ..
git clone https://git.zx2c4.com/wireguard-go
Expand All @@ -43,67 +71,68 @@ jobs:
go build -v -o "wireguard-go"
sudo ./wireguard-go utun15
- name: Install dependencies
run: npm install --no-save --ignore-scripts

- name: Test
run: |
tsc --build --clean
tsc --build
sudo -E mocha ./src
run: npm run prebuildify -- -v && sudo -E ./node_modules/.bin/mocha ./src

- name: Upload generate interface
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}_${{ matrix.node_version }}
name: addrs_${{ runner.os }}_${{ matrix.node_version }}
path: "*.addrs.json"

build:
needs: test
- name: Upload generate interface
uses: actions/upload-artifact@v3
with:
retention-days: 7
name: prebuilds_${{ runner.os }}
path: "prebuilds/**"

win_test:
runs-on: windows-latest
strategy:
matrix:
os:
- windows
- macos
runs-on: ${{ matrix.os }}-latest
node_version: [ 16.x, 17.x, 18.x, 19.x ]
steps:
- uses: actions/checkout@v4
name: Code checkout
with:
submodules: true
name: Checkout

# Install basic tools
- uses: actions/setup-node@v3
name: Setup node.js
name: Setup Node.js
with:
node-version: 18.x
registry-url: https://registry.npmjs.org/
node-version: ${{ matrix.node_version }}

- run: npm install --no-save --ignore-scripts
- run: npm run prebuildify -- -v
- name: Install dependencies
run: npm install --no-save --ignore-scripts

- name: Test
run: npm run prebuildify -- -v && ./node_modules/.bin/mocha ./src

- name: Upload generate interface
uses: actions/upload-artifact@v3
with:
name: addrs_${{ runner.os }}_${{ matrix.node_version }}
path: "*.addrs.json"

- name: Upload generate interface
uses: actions/upload-artifact@v3
with:
retention-days: 7
name: prebuilds_${{ matrix.os }}
name: prebuilds_${{ runner.os }}
path: "prebuilds/**"

pack_package:
needs: build
needs: [ linux_test, macos_test, win_test ]
runs-on: ubuntu-latest
name: Pack npm package
env:
PACKAGE_VERSION: ${{ github.ref }}
steps:
- uses: actions/checkout@v4
name: Code checkout
with:
submodules: true

- name: Ubuntu dependecies
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt install -y binutils-multiarch gcc-*aarch64-linux-gnu gcc-*aarch64-linux-gnu-base g++-*aarch64-linux-gnu libc6-arm64-cross
# Install basic tools
- uses: actions/setup-node@v3
name: Setup node.js
with:
Expand All @@ -115,7 +144,7 @@ jobs:
with:
path: ./prebuilds

- run: npm install --no-save
- run: npm install --no-save --ignore-scripts
- run: npm pack

- name: Upload npm package
Expand Down
15 changes: 8 additions & 7 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
"-static"
],
"defines": [
"NAPI_DISABLE_CPP_EXCEPTIONS"
"NAPI_DISABLE_CPP_EXCEPTIONS",
"DELIFACE",
"SETCONFIG",
"ONSTARTADDON"
],
"includePath": [
"${env:appdata}/../Local/node-gyp/Cache/18.17.0/include/node",
"${workspaceFolder}/node_modules/node-addon-api",
"${workspaceFolder}/addons/**",
"${workspaceFolder}/addons"
"${workspaceFolder}/addons/tools/**"
]
},
{
Expand All @@ -45,16 +47,15 @@
"/usr/include/node",
"${workspaceFolder}/node_modules/node-addon-api/**",
"${workspaceFolder}/node_modules/**",
"${workspaceFolder}/addons/**",
"${workspaceFolder}/addons"
"${workspaceFolder}/addons/tools/**"
]
},
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/node_modules/node-addon-api",
"${workspaceFolder}/addons/**",
"/usr/local/include/node"
"/usr/local/include/node",
"${workspaceFolder}/addons/tools/**"
],
"defines": [
"NAPI_DISABLE_CPP_EXCEPTIONS"
Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@
},
"terminal.integrated.env.osx": {
"PATH": "${workspaceFolder}/node_modules/.bin:${env:PATH}"
},
"files.associations": {
"*.dsc": "ini",
"*.gyp": "python",
"vector": "cpp"
}
}
4 changes: 4 additions & 0 deletions addons/tools/wginterface-dummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ unsigned long maxName() {
return IFNAMSIZ;
}

std::string versionDrive() {
return "Userspace";
}

void listDevices::Execute() {}
void deleteInterface::Execute() {}
void setConfig::Execute() {}
Expand Down
14 changes: 8 additions & 6 deletions addons/tools/wginterface-linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ unsigned long maxName() {
return IFNAMSIZ;
}

std::string versionDrive() {
return "Kernel";
}

void listDevices::Execute() {
char *device_name, *devicesList = wg_list_device_names();
if (!devicesList) SetError("Unable to get device names");
else {
size_t len;
for ((device_name) = (devicesList), (len) = 0; ((len) = strlen(device_name)); (device_name) += (len) + 1) deviceNames.push_back(device_name);
free(devicesList);
}
if (!devicesList) return SetError("Unable to get device names");
size_t len;
for ((device_name) = (devicesList), (len) = 0; ((len) = strlen(device_name)); (device_name) += (len) + 1) deviceNames[std::string(device_name)] = "kernel";
free(devicesList);
}

int setInterface(std::string wgName) {
Expand Down
Loading

0 comments on commit 1ed4fca

Please sign in to comment.