diff --git a/CMakeLists.txt b/CMakeLists.txt
index dbd61e5..37dfc9d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8.12)
+cmake_minimum_required(VERSION 3.10)
project(sai C)
find_package(libwebsockets CONFIG REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR})
@@ -155,9 +155,9 @@ if (requirements)
if (SAI_BUILDER)
add_subdirectory(src/builder)
add_subdirectory(src/resource)
- add_subdirectory(src/power)
if (NOT MSVC AND NOT WIN32 AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "SunOS"))
+ add_subdirectory(src/power)
add_subdirectory(src/device)
add_subdirectory(src/expect)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
diff --git a/README.md b/README.md
index 425a62f..ae2822d 100644
--- a/README.md
+++ b/README.md
@@ -344,6 +344,38 @@ $ sudo vim /etc/sai/builder/conf
$ sudo systemctl enable sai-builder
```
+#### Windows builder only
+
+Build libgit2 via vcpkg, this takes <10mins
+
+```
+> vcpkg install libgit2:x64-windows
+```
+
+You have to make git2.dll and some deps visible, in /windows/system32 or similar
+
+```
+> sudo cp "\Users\<user>\vcpkg\installed\x64-windows\bin\pcre.dll" "\windows\system32"
+> sudo cp "\Users\<user>\vcpkg\libgit2_x64-windows\bin\git2.dll" "\windows\system32"
+```
+
+Build lws the same way as for unix, except with
+
+```
+> cmake --build . --config DEBUG
+> sudo cmake --install . --config DEBUG
+```
+
+For sai it's also very similar to unix, but with
+
+```
+> cmake .. -DSAI_SERVER=0 -DSAI_LWS_INC_PATH="\Users\<user>\libwebsockets\build\include" -DSAI_LWS_LIB_PATH="\Users\<user>\libwebsockets\build\lib\Debug\websockets.lib" -DSAI_GIT2_INC_PATH="\Users\<user>\vcpkg\packages\libgit2_x64-windows\include" -DSAI_GIT2_LIB_PATH="\Users\<user>\vcpkg\packages\libgit2_x64-windows\lib\git2.lib" -DSAI_EXT_PTHREAD_INCLUDE_DIR="C:\Program Files (x86)\pthreads\include" -DSAI_EXT_PTHREAD_LIBRARIES="C:\Program Files (x86)\pthreads\lib\x64\libpthreadGC2.a"
+> cmake --build . --config DEBUG
+> sudo cmake --install . --config DEBUG
+```
+
+On Windows, the config exists in `C:\ProgramData\sai\builder\conf` rather than \etc.
+
#### Additional steps for freebsd
Freebsd presents a few differences from Linux.
diff --git a/assets/w11.svg b/assets/w11.svg
new file mode 100644
index 0000000..fbdd1a2
--- /dev/null
+++ b/assets/w11.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3.886 3.886" height="14.687" width="14.687"><circle r="1.943" cy="1.943" cx="1.943" fill="#f9f9f9" fill-opacity=".12"/><path d="M2.498 3.044l-.558-.08-.16-.02v-.886h1.218V3.11h-.05c-.03 0-.23-.03-.45-.06zM1.18 2.86L.75 2.8v-.764h.917v.44c0 .412 0 .44-.03.44-.02 0-.225-.03-.46-.06zM.745 1.564c0-.38 0-.382.04-.39.04 0 .84-.118.87-.118.01 0 .02.176.02.433v.434l-.04.01-.463.01H.748zm1.035-.08V1.04l.05-.01c.03 0 .28-.04.558-.08l.56-.08h.05v1.07H1.78z" fill="#000000"/></svg>
diff --git a/src/builder/b-mirror.c b/src/builder/b-mirror.c
index 75d2657..ac32dc8 100644
--- a/src/builder/b-mirror.c
+++ b/src/builder/b-mirror.c
@@ -71,18 +71,22 @@ sai_mirror_local_checkout(struct sai_nspawn *ns)
git_checkout_options co_opts = GIT_CHECKOUT_OPTIONS_INIT;
git_fetch_options opts = GIT_FETCH_OPTIONS_INIT;
git_repository *git_repo_build_specific = NULL;
- char dp[512], spec[256], *paths[] = { spec };
+ char dp[512], spec[256], *paths[] = { spec }, inp[512];
git_strarray rfs = { paths, 1 };
git_object *treeish;
git_remote *remote;
int n, tries = 2;
+ lws_strncpy(inp, ns->inp, sizeof(inp) - 1);
+ if (inp[strlen(inp) - 1] == '\\')
+ inp[strlen(inp) - 1] = '\0';
+
/*
* Remove anything that was already in the build-specific dir
*/
- lwsl_notice("%s: rm -rf %s\n", __func__, ns->inp);
- lws_dir(ns->inp, NULL, lws_dir_rm_rf_cb);
+ lwsl_notice("%s: rm -rf %s\n", __func__, inp);
+ lws_dir(inp, NULL, lws_dir_rm_rf_cb);
/*
* Make sure the build-specific dir itself is left standing in there.
@@ -91,14 +95,14 @@ sai_mirror_local_checkout(struct sai_nspawn *ns)
* credentials since we have dropped root long ago
*/
- if (mkdir(ns->inp, 0755))
+ if (mkdir(inp, 0755))
lwsl_notice("%s: mkdir %s failed\n", __func__, ns->inp);
/*
* Create the build-specific git dir and init it
*/
- n = git_repository_init(&git_repo_build_specific, ns->inp, 0);
+ n = git_repository_init(&git_repo_build_specific, inp, 0);
if (n) {
#if defined(SAI_HAVE_LIBGIT2_GIT_ERROR)
const git_error *e = git_error_last();
@@ -110,7 +114,7 @@ sai_mirror_local_checkout(struct sai_nspawn *ns)
__func__, ns->inp, n);
#endif
- return 1;
+ return SAIB_CHECKOUT_CHECKOUT_FAILED;
}
/*
@@ -125,7 +129,7 @@ sai_mirror_local_checkout(struct sai_nspawn *ns)
ns->git_repo_url);
git_repository_free(git_repo_build_specific);
- return 1;
+ return SAIB_CHECKOUT_CHECKOUT_FAILED;
}
lws_snprintf(spec, sizeof(spec), "ref-%s:ref-%s", ns->hash, ns->hash);
@@ -362,7 +366,7 @@ saib_mirror_task(void *user, enum lws_threadpool_task_status s)
case SAIB_CHECKOUT_NOT_IN_LOCAL_MIRROR:
/* fallthru */
- lwsl_notice("%s: checkout not it local mirror\n", __func__);
+ lwsl_notice("%s: checkout not in local mirror\n", __func__);
case SAIB_CHECKOUT_CHECKOUT_FAILED:
lws_snprintf(ns->pending_mirror_log,
diff --git a/src/builder/b-sai.c b/src/builder/b-sai.c
index 267d21a..8cf95e5 100644
--- a/src/builder/b-sai.c
+++ b/src/builder/b-sai.c
@@ -45,6 +45,10 @@
#include <KnownFolders.h>
#include <Shlobj.h>
+#if !defined(PATH_MAX)
+#define PATH_MAX MAX_PATH
+#endif
+
int getpid(void) { return 0; }
#endif
@@ -582,6 +586,7 @@ LWS_SS_INFO("sai_power", saib_power_link_t)
void
sul_idle_cb(lws_sorted_usec_list_t *sul)
{
+#if !defined(WIN32)
ssize_t n;
uint8_t te = 1;
@@ -597,7 +602,11 @@ sul_idle_cb(lws_sorted_usec_list_t *sul)
n = write(lws_spawn_get_fd_stdxxx(lsp_suspender, 0), &te, 1);
if (n == 1) {
+#if defined(WIN32)
+ Sleep(2000);
+#else
sleep(2);
+#endif
/*
* There were 0 tasks ongoing for us to suspend, start off
* with the same assumption and set the idle grace time
@@ -635,7 +644,11 @@ sul_idle_cb(lws_sorted_usec_list_t *sul)
* everything including the http as soon as we progress on to shutdown)
*/
+#if defined(WIN32)
+ Sleep(2000);
+#else
sleep(2);
+#endif
lwsl_notice("%s: doing shutdown...\n", __func__);
@@ -646,6 +659,7 @@ sul_idle_cb(lws_sorted_usec_list_t *sul)
te = 0;
n = write(lws_spawn_get_fd_stdxxx(lsp_suspender, 0), &te, 1);
+#endif
}
static lws_state_notify_link_t * const app_notifier_list[] = {
@@ -690,6 +704,7 @@ int main(int argc, const char **argv)
const char *p;
void *retval;
+#if !defined(WIN32)
if ((p = lws_cmdline_option(argc, argv, "-s"))) {
ssize_t n = 0;
@@ -742,6 +757,7 @@ int main(int argc, const char **argv)
return 0;
}
+#endif
if ((p = lws_cmdline_option(argc, argv, "-d")))
logs = atoi(p);
@@ -776,7 +792,7 @@ int main(int argc, const char **argv)
}
lws_snprintf(stg_config_dir, sizeof(stg_config_dir),
- "%s\\sai\\builder\\", temp);
+ "%s\\sai\\builder", temp);
config_dir = stg_config_dir;
CoTaskMemFree(wdi);
@@ -884,6 +900,7 @@ int main(int argc, const char **argv)
goto bail;
}
+#if !defined(WIN32)
{
struct lws_spawn_piped_info info;
char rpath[PATH_MAX];
@@ -912,6 +929,7 @@ int main(int argc, const char **argv)
lws_sul_schedule(builder.context, 0, &builder.sul_idle,
sul_idle_cb, SAI_IDLE_GRACE_US);
}
+#endif
pthread_mutex_init(&builder.mi.mut, NULL);
pthread_cond_init(&builder.mi.cond, NULL);
diff --git a/src/web/CMakeLists.txt b/src/web/CMakeLists.txt
index 6589eb2..b132dfb 100644
--- a/src/web/CMakeLists.txt
+++ b/src/web/CMakeLists.txt
@@ -141,6 +141,7 @@ if (requirements)
../../assets/ubuntu-focal-aarch64.svg
../../assets/virt-qemu.svg
../../assets/w10.svg
+ ../../assets/w11.svg
DESTINATION "${DATA_DIR}/sai/assets"
COMPONENT web)