windows cross-compilation
This commit is contained in:
parent
36227f99e5
commit
380d38229d
|
@ -53,3 +53,31 @@ jobs:
|
||||||
args: --release --bin tfclient
|
args: --release --bin tfclient
|
||||||
- name: Upload binary
|
- name: Upload binary
|
||||||
run: sshpass -p "${{ secrets.TRIFID_DLCDN_PASSWORD }}" rsync --mkpath -e 'ssh -p ${{ secrets.TRIFID_DLCDN_PORT }} -o StrictHostKeyChecking=no' target/release/tfclient ${{ secrets.TRIFID_DLCDN_USER }}@${{ secrets.TRIFID_DLCDN_IP }}:${{ secrets.TRIFID_DLCDN_PATH }}/tfclient/arm64/$GITHUB_SHA/tfclient
|
run: sshpass -p "${{ secrets.TRIFID_DLCDN_PASSWORD }}" rsync --mkpath -e 'ssh -p ${{ secrets.TRIFID_DLCDN_PORT }} -o StrictHostKeyChecking=no' target/release/tfclient ${{ secrets.TRIFID_DLCDN_USER }}@${{ secrets.TRIFID_DLCDN_IP }}:${{ secrets.TRIFID_DLCDN_PATH }}/tfclient/arm64/$GITHUB_SHA/tfclient
|
||||||
|
build_win64:
|
||||||
|
runs_on: docker
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Setup Go toolchain
|
||||||
|
uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: '1.20'
|
||||||
|
- name: Setup Rust toolchain
|
||||||
|
uses: https://github.com/actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
- name: Install cross-compilation toolchain
|
||||||
|
run: rustup target add x86_64-pc-windows-gnu
|
||||||
|
- name: Install additional dependencies
|
||||||
|
run: apt update && apt-get install -y libclang-dev clang sshpass rsync
|
||||||
|
- name: Compile release binary
|
||||||
|
uses: https://github.com/actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: build
|
||||||
|
args: --release --bin tfclient --target x86_64-pc-windows-gnu
|
||||||
|
- name: Compile release bundle
|
||||||
|
run: ./build_windows.sh
|
||||||
|
- name: Upload binary
|
||||||
|
run: sshpass -p "${{ secrets.TRIFID_DLCDN_PASSWORD }}" rsync --mkpath -e 'ssh -p ${{ secrets.TRIFID_DLCDN_PORT }} -o StrictHostKeyChecking=no' target/release/x86_64-pc-windows-gnu/tfclient.zip ${{ secrets.TRIFID_DLCDN_USER }}@${{ secrets.TRIFID_DLCDN_IP }}:${{ secrets.TRIFID_DLCDN_PATH }}/tfclient/win64/$GITHUB_SHA/tfclient.zip
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
<data-source source="LOCAL" name="trifidapi@localhost" uuid="39c81b89-3fc4-493f-b203-7a00527cffe6">
|
<data-source source="LOCAL" name="trifid@localhost" uuid="39c81b89-3fc4-493f-b203-7a00527cffe6">
|
||||||
<driver-ref>postgresql</driver-ref>
|
<driver-ref>postgresql</driver-ref>
|
||||||
<synchronize>true</synchronize>
|
<synchronize>true</synchronize>
|
||||||
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
|
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
cargo build --target x86_64-pc-windows-gnu --release --bin tfclient
|
||||||
|
rm -rf target/x86_64-pc-windows-gnu/release/tfclient_dist/
|
||||||
|
mkdir -p target/x86_64-pc-windows-gnu/release/tfclient_dist/
|
||||||
|
cp target/x86_64-pc-windows-gnu/release/tfclient.exe target/x86_64-pc-windows-gnu/release/tfclient_dist/tfclient.exe
|
||||||
|
echo "[*] Downloading WinTun"
|
||||||
|
mkdir -p target/x86_64-pc-windows-gnu/release/tfclient_dist/dist/windows/
|
||||||
|
wget https://www.wintun.net/builds/wintun-0.14.1.zip -O /tmp/wintun.zip
|
||||||
|
echo "[*] Unzipping WinTun"
|
||||||
|
unzip -d target/x86_64-pc-windows-gnu/release/tfclient_dist/dist/windows/ /tmp/wintun.zip
|
||||||
|
echo "[*] Copying nebula.dll"
|
||||||
|
cp target/x86_64-pc-windows-gnu/release/nebula.dll target/x86_64-pc-windows-gnu/release/tfclient_dist/nebula.dll
|
||||||
|
echo "[*] Building zip bundle"
|
||||||
|
cd target/x86_64-pc-windows-gnu/release
|
||||||
|
zip -r tfclient.zip tfclient_dist/*
|
||||||
|
cd ../../../
|
||||||
|
echo "[*] Windows production build success!"
|
|
@ -3,6 +3,22 @@ use std::path::PathBuf;
|
||||||
use bindgen::CargoCallbacks;
|
use bindgen::CargoCallbacks;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
fn get_cargo_target_dir() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
|
||||||
|
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR")?);
|
||||||
|
let profile = std::env::var("PROFILE")?;
|
||||||
|
let mut target_dir = None;
|
||||||
|
let mut sub_path = out_dir.as_path();
|
||||||
|
while let Some(parent) = sub_path.parent() {
|
||||||
|
if parent.ends_with(&profile) {
|
||||||
|
target_dir = Some(parent);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sub_path = parent;
|
||||||
|
}
|
||||||
|
let target_dir = target_dir.ok_or("not found")?;
|
||||||
|
Ok(target_dir.to_path_buf())
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
// Find compiler:
|
// Find compiler:
|
||||||
|
@ -29,7 +45,7 @@ fn main() {
|
||||||
|
|
||||||
let out_dir = env::var("OUT_DIR").unwrap();
|
let out_dir = env::var("OUT_DIR").unwrap();
|
||||||
let out_path = PathBuf::from(out_dir);
|
let out_path = PathBuf::from(out_dir);
|
||||||
let out_file = LIBRARY_PREFIX.to_owned() + "nebula" + LIBRARY_EXTENSION;
|
let out_file = lib_name();
|
||||||
let out = out_path.join(out_file);
|
let out = out_path.join(out_file);
|
||||||
|
|
||||||
let mut command = process::Command::new(compiler);
|
let mut command = process::Command::new(compiler);
|
||||||
|
@ -49,6 +65,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Go compile success");
|
println!("Go compile success");
|
||||||
|
copy_if_windows();
|
||||||
|
|
||||||
print_link();
|
print_link();
|
||||||
println!("cargo:rustc-link-search=native={}", env::var("OUT_DIR").unwrap());
|
println!("cargo:rustc-link-search=native={}", env::var("OUT_DIR").unwrap());
|
||||||
|
@ -63,7 +80,7 @@ fn main() {
|
||||||
println!("Generating bindings");
|
println!("Generating bindings");
|
||||||
|
|
||||||
let bindings = bindgen::Builder::default()
|
let bindings = bindgen::Builder::default()
|
||||||
.header(out_path.join(LIBRARY_PREFIX.to_owned() + "nebula.h").display().to_string())
|
.header(out_path.join(header_name()).display().to_string())
|
||||||
.parse_callbacks(Box::new(CargoCallbacks))
|
.parse_callbacks(Box::new(CargoCallbacks))
|
||||||
.generate()
|
.generate()
|
||||||
.expect("Error generating CFFI bindings");
|
.expect("Error generating CFFI bindings");
|
||||||
|
@ -74,15 +91,30 @@ fn main() {
|
||||||
.expect("Couldn't write bindings!");
|
.expect("Couldn't write bindings!");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_family = "unix")]
|
fn lib_name() -> String {
|
||||||
const LIBRARY_EXTENSION: & str = ".a";
|
if env::var("CARGO_CFG_TARGET_FAMILY").unwrap() == "windows" {
|
||||||
#[cfg(target_family = "unix")]
|
"nebula.dll".to_string()
|
||||||
const LIBRARY_PREFIX: & str = "lib";
|
} else {
|
||||||
|
"libnebula.a".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn header_name() -> String {
|
||||||
|
if env::var("CARGO_CFG_TARGET_FAMILY").unwrap() == "windows" {
|
||||||
|
"nebula.h".to_string()
|
||||||
|
} else {
|
||||||
|
"libnebula.h".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_family = "windows")]
|
fn copy_if_windows() {
|
||||||
const LIBRARY_EXTENSION: &str = ".dll";
|
let target_dir = get_cargo_target_dir().unwrap();
|
||||||
#[cfg(target_family = "windows")]
|
let target_file = target_dir.join(lib_name());
|
||||||
const LIBRARY_PREFIX: &str = "";
|
let out_dir = env::var("OUT_DIR").unwrap();
|
||||||
|
let out_path = PathBuf::from(out_dir);
|
||||||
|
let out_file = lib_name();
|
||||||
|
let out = out_path.join(out_file);
|
||||||
|
std::fs::copy(out, target_file).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
fn goarch() -> String {
|
fn goarch() -> String {
|
||||||
match env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() {
|
match env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() {
|
||||||
|
@ -111,19 +143,18 @@ fn goos() -> String {
|
||||||
}.to_string()
|
}.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_family = "unix")]
|
|
||||||
fn print_link() {
|
fn print_link() {
|
||||||
|
if env::var("CARGO_CFG_TARGET_FAMILY").unwrap() == "windows" {
|
||||||
|
println!("cargo:rustc-link-lib=dylib=nebula");
|
||||||
|
} else {
|
||||||
println!("cargo:rustc-link-lib=static=nebula");
|
println!("cargo:rustc-link-lib=static=nebula");
|
||||||
}
|
}
|
||||||
#[cfg(target_family = "unix")]
|
}
|
||||||
|
|
||||||
fn link_type() -> String {
|
fn link_type() -> String {
|
||||||
|
if env::var("CARGO_CFG_TARGET_FAMILY").unwrap() == "windows" {
|
||||||
|
"c-shared".to_string()
|
||||||
|
} else {
|
||||||
"c-archive".to_string()
|
"c-archive".to_string()
|
||||||
}
|
}
|
||||||
#[cfg(target_family = "windows")]
|
|
||||||
fn print_link() {
|
|
||||||
println!("cargo:rustc-link-lib=dylib=nebula");
|
|
||||||
}
|
|
||||||
#[cfg(target_family = "windows")]
|
|
||||||
fn link_type() -> String {
|
|
||||||
"c-shared".to_string()
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue