Skip to content

Commit

Permalink
Cross compiling for windows kinda works
Browse files Browse the repository at this point in the history
  • Loading branch information
Okabintaro committed Nov 29, 2022
1 parent ebc5abf commit 3f87b32
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 162 deletions.
47 changes: 32 additions & 15 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,22 @@ pub fn build(b: *std.build.Builder) void {
whisper_osc.install();
whisper_osc.linkLibrary(whisper);
whisper_osc.linkLibrary(tinyosc);
whisper_osc.linkSystemLibrary("SDL2");

if (whisper_osc.target.isWindows()) {
whisper_osc.addLibPath("SDL2-2.26.0/x86_64-w64-mingw32/lib/");
whisper_osc.addIncludeDir("./SDL2-2.26.0/x86_64-w64-mingw32/include/SDL2");
whisper_osc.defineCMacro("SDL_MAIN_HANDLED", "1");
whisper_osc.linkSystemLibraryName("SDL2");
whisper_osc.linkSystemLibrary("wsock32");
whisper_osc.linkSystemLibrary("pthread");
whisper_osc.linkSystemLibrary("ws2_32");
whisper_osc.linkSystemLibrary("c");
whisper_osc.linkSystemLibrary("gdi32");
whisper_osc.linkSystemLibrary("user32");
whisper_osc.linkSystemLibrary("kernel32");
} else {
whisper_osc.linkSystemLibrary("SDL2");
}

const run_cmd = whisper_osc.run();
run_cmd.step.dependOn(b.getInstallStep());
Expand All @@ -79,20 +94,22 @@ pub fn build(b: *std.build.Builder) void {
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);

const tinyosc_main = b.addExecutable("tinyosc_main", null);
tinyosc_main.setTarget(target);
tinyosc_main.setBuildMode(mode);
tinyosc_main.addIncludeDir("./deps/tinyosc");
tinyosc_main.addCSourceFile("./deps/tinyosc/main.c", &.{});
tinyosc_main.linkLibC();
tinyosc_main.install();
tinyosc_main.linkLibrary(tinyosc);
if (target.isLinux()) {
const tinyosc_main = b.addExecutable("tinyosc_main", null);
tinyosc_main.setTarget(target);
tinyosc_main.setBuildMode(mode);
tinyosc_main.addIncludeDir("./deps/tinyosc");
tinyosc_main.addCSourceFile("./deps/tinyosc/main.c", &.{});
tinyosc_main.linkLibC();
tinyosc_main.install();
tinyosc_main.linkLibrary(tinyosc);

const run_osc_cmd = tinyosc_main.run();
run_osc_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
const run_osc_cmd = tinyosc_main.run();
run_osc_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_osc_step = b.step("listen_osc", "Run the tinyosc sample");
run_osc_step.dependOn(&run_osc_cmd.step);
}
const run_osc_step = b.step("listen_osc", "Run the tinyosc sample");
run_osc_step.dependOn(&run_osc_cmd.step);
}
26 changes: 22 additions & 4 deletions cpp/whisper_osc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@
#include <thread>
#include <vector>

#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#ifdef _WIN32
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#endif

// 500 -> 00:05.000
// 6000 -> 01:00.000
Expand Down Expand Up @@ -316,6 +325,15 @@ int main(int argc, char **argv) {
int sockfd;
struct sockaddr_in addr;

#if _WIN32
WSADATA wsa;
// Initialise winsock
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) {
printf("Failed initializing winsock. Error: %d", WSAGetLastError());
return -1;
}
#endif

if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("Failure creating socket");
return -1;
Expand Down Expand Up @@ -451,7 +469,7 @@ int main(int argc, char **argv) {

// send the data out of the socket
// send(socket_fd, buffer, len, 0);
sendto(sockfd, (const char *)buffer, len, MSG_CONFIRM,
sendto(sockfd, (const char *)buffer, len, 0,
(struct sockaddr *)&addr, sizeof(addr));
}

Expand Down
Loading

0 comments on commit 3f87b32

Please sign in to comment.