Skip to content

Commit

Permalink
Merge pull request #8901 from nix-windows/mingw
Browse files Browse the repository at this point in the history
Build a minimized Nix with MinGW
  • Loading branch information
Ericson2314 authored Apr 17, 2024
2 parents 05b9dac + 1063aa5 commit ac253fb
Show file tree
Hide file tree
Showing 120 changed files with 1,436 additions and 342 deletions.
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ clean-files += $(buildprefix)Makefile.config

# List makefiles

include mk/platform.mk

ifeq ($(ENABLE_BUILD), yes)
makefiles = \
mk/precompiled-headers.mk \
Expand All @@ -20,7 +22,10 @@ makefiles = \
src/nix/local.mk \
src/libutil-c/local.mk \
src/libstore-c/local.mk \
src/libexpr-c/local.mk \
src/libexpr-c/local.mk

ifdef HOST_UNIX
makefiles += \
scripts/local.mk \
misc/bash/local.mk \
misc/fish/local.mk \
Expand All @@ -29,6 +34,7 @@ makefiles = \
misc/launchd/local.mk \
misc/upstart/local.mk
endif
endif

ifeq ($(ENABLE_UNIT_TESTS), yes)
makefiles += \
Expand All @@ -42,6 +48,7 @@ makefiles += \
endif

ifeq ($(ENABLE_FUNCTIONAL_TESTS), yes)
ifdef HOST_UNIX
makefiles += \
tests/functional/local.mk \
tests/functional/ca/local.mk \
Expand All @@ -51,6 +58,7 @@ makefiles += \
tests/functional/test-libstoreconsumer/local.mk \
tests/functional/plugins/local.mk
endif
endif

# Some makefiles require access to built programs and must be included late.
makefiles-late =
Expand Down Expand Up @@ -79,8 +87,6 @@ else
unexport NIX_HARDENING_ENABLE
endif

include mk/platform.mk

ifdef HOST_WINDOWS
# Windows DLLs are stricter about symbol visibility than Unix shared
# objects --- see https://gcc.gnu.org/wiki/Visibility for details.
Expand Down
12 changes: 3 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
"armv6l-unknown-linux-gnueabihf"
"armv7l-unknown-linux-gnueabihf"
"x86_64-unknown-netbsd"
];

# Nix doesn't yet build on this platform, so we put it in a
# separate list. We just use this for `devShells` and
# `nixpkgsFor`, which this depends on.
shellCrossSystems = crossSystems ++ [
"x86_64-w64-mingw32"
];

Expand Down Expand Up @@ -83,7 +77,7 @@
in {
inherit stdenvs native;
static = native.pkgsStatic;
cross = lib.genAttrs shellCrossSystems (crossSystem: make-pkgs crossSystem "stdenv");
cross = forAllCrossSystems (crossSystem: make-pkgs crossSystem "stdenv");
});

installScriptFor = tarballs:
Expand Down Expand Up @@ -426,8 +420,8 @@
in
(makeShells "native" nixpkgsFor.${system}.native) //
(lib.optionalAttrs (!nixpkgsFor.${system}.native.stdenv.isDarwin)
(makeShells "static" nixpkgsFor.${system}.static)) //
(lib.genAttrs shellCrossSystems (crossSystem: let pkgs = nixpkgsFor.${system}.cross.${crossSystem}; in makeShell pkgs pkgs.stdenv)) //
(makeShells "static" nixpkgsFor.${system}.static) //
(forAllCrossSystems (crossSystem: let pkgs = nixpkgsFor.${system}.cross.${crossSystem}; in makeShell pkgs pkgs.stdenv))) //
{
default = self.devShells.${system}.native-stdenvPackages;
}
Expand Down
8 changes: 5 additions & 3 deletions m4/gcc_bug_80431.m4
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ AC_DEFUN([ENSURE_NO_GCC_BUG_80431],
]])],
[status_80431=0],
[status_80431=$?],
[
# Assume we're bug-free when cross-compiling
])
[status_80431=''])
AC_LANG_POP(C++)
AS_CASE([$status_80431],
[''],[
AC_MSG_RESULT(cannot check because cross compiling)
AC_MSG_NOTICE(assume we are bug free)
],
[0],[
AC_MSG_RESULT(yes)
],
Expand Down
21 changes: 12 additions & 9 deletions precompiled-headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,22 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <netdb.h>
#include <pwd.h>
#include <signal.h>
#include <sys/resource.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/wait.h>
#include <termios.h>
#include <unistd.h>

#ifndef _WIN32
# include <grp.h>
# include <netdb.h>
# include <pwd.h>
# include <sys/resource.h>
# include <sys/select.h>
# include <sys/socket.h>
# include <sys/utsname.h>
# include <sys/wait.h>
# include <termios.h>
#endif

#include <nlohmann/json.hpp>
1 change: 1 addition & 0 deletions src/build-remote/build-remote.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "experimental-features.hh"

using namespace nix;
using namespace nix::unix;
using std::cin;

static void handleAlarm(int sig) {
Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/common-eval-args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
v->mkString(arg.s);
},
[&](const AutoArgFile & arg) {
v->mkString(readFile(arg.path));
v->mkString(readFile(arg.path.string()));
},
[&](const AutoArgStdin & arg) {
v->mkString(readFile(STDIN_FILENO));
Expand Down
4 changes: 2 additions & 2 deletions src/libcmd/markdown.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "finally.hh"
#include "terminal.hh"

#include <sys/queue.h>
#if HAVE_LOWDOWN
#include <lowdown.h>
# include <sys/queue.h>
# include <lowdown.h>
#endif

namespace nix {
Expand Down
4 changes: 4 additions & 0 deletions src/libcmd/repl-interacter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ static constexpr const char * promptForType(ReplPromptType promptType)

bool ReadlineLikeInteracter::getLine(std::string & input, ReplPromptType promptType)
{
#ifndef _WIN32 // TODO use more signals.hh for this
struct sigaction act, old;
sigset_t savedSignalMask, set;

Expand All @@ -161,9 +162,12 @@ bool ReadlineLikeInteracter::getLine(std::string & input, ReplPromptType promptT
};

setupSignals();
#endif
char * s = readline(promptForType(promptType));
Finally doFree([&]() { free(s); });
#ifndef _WIN32 // TODO use more signals.hh for this
restoreSignals();
#endif

if (g_signal_received) {
g_signal_received = 0;
Expand Down
10 changes: 8 additions & 2 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@
#include <optional>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <fstream>
#include <functional>
#include <iostream>

#include <sys/resource.h>
#include <nlohmann/json.hpp>
#include <boost/container/small_vector.hpp>

#ifndef _WIN32 // TODO use portable implementation
# include <sys/resource.h>
#endif

#if HAVE_BOEHMGC

#define GC_INCLUDE_NEW
Expand Down Expand Up @@ -2627,9 +2629,11 @@ void EvalState::maybePrintStats()

void EvalState::printStatistics()
{
#ifndef _WIN32 // TODO use portable implementation
struct rusage buf;
getrusage(RUSAGE_SELF, &buf);
float cpuTime = buf.ru_utime.tv_sec + ((float) buf.ru_utime.tv_usec / 1000000);
#endif

uint64_t bEnvs = nrEnvs * sizeof(Env) + nrValuesInEnvs * sizeof(Value *);
uint64_t bLists = nrListElems * sizeof(Value *);
Expand All @@ -2646,7 +2650,9 @@ void EvalState::printStatistics()
if (outPath != "-")
fs.open(outPath, std::fstream::out);
json topObj = json::object();
#ifndef _WIN32 // TODO implement
topObj["cpuTime"] = cpuTime;
#endif
topObj["envs"] = {
{"number", nrEnvs},
{"elements", nrValuesInEnvs},
Expand Down
2 changes: 2 additions & 0 deletions src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ struct DebugTrace {
bool isError;
};

// Don't want Windows function
#undef SearchPath

class EvalState : public std::enable_shared_from_this<EvalState>
{
Expand Down
11 changes: 10 additions & 1 deletion src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
#include <algorithm>
#include <cstring>
#include <regex>
#include <dlfcn.h>

#ifndef _WIN32
# include <dlfcn.h>
#endif

#include <cmath>

Expand Down Expand Up @@ -331,6 +334,8 @@ static RegisterPrimOp primop_import({
}
});

#ifndef _WIN32 // TODO implement via DLL loading on Windows

/* Want reasonable symbol names, so extern C */
/* !!! Should we pass the Pos or the file name too? */
extern "C" typedef void (*ValueInitializer)(EvalState & state, Value & v);
Expand Down Expand Up @@ -403,6 +408,8 @@ void prim_exec(EvalState & state, const PosIdx pos, Value * * args, Value & v)
}
}

#endif

/* Return a string representing the type of the expression. */
static void prim_typeOf(EvalState & state, const PosIdx pos, Value * * args, Value & v)
{
Expand Down Expand Up @@ -4593,6 +4600,7 @@ void EvalState::createBaseEnv()
)",
});

#ifndef _WIN32 // TODO implement on Windows
// Miscellaneous
if (evalSettings.enableNativeCode) {
addPrimOp({
Expand All @@ -4606,6 +4614,7 @@ void EvalState::createBaseEnv()
.fun = prim_exec,
});
}
#endif

addPrimOp({
.name = "__traceVerbose",
Expand Down
3 changes: 3 additions & 0 deletions src/libexpr/search-path.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

namespace nix {

// Do not want the windows macro (alias to `SearchPathA`)
#undef SearchPath

/**
* A "search path" is a list of ways look for something, used with
* `builtins.findFile` and `< >` lookup expressions.
Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/fs-input-accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ref<InputAccessor> makeStorePathAccessor(
// FIXME: should use `store->getFSAccessor()`
auto root = std::filesystem::path { store->toRealPath(storePath) };
auto accessor = makeFSInputAccessor(root);
accessor->setPathDisplay(root);
accessor->setPathDisplay(root.string());
return accessor;
}

Expand Down
16 changes: 8 additions & 8 deletions src/libfetchers/git-utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
{
initLibGit2();

if (pathExists(path.native())) {
if (git_repository_open(Setter(repo), path.c_str()))
if (pathExists(path.string())) {
if (git_repository_open(Setter(repo), path.string().c_str()))
throw Error("opening Git repository '%s': %s", path, git_error_last()->message);
} else {
if (git_repository_init(Setter(repo), path.c_str(), bare))
if (git_repository_init(Setter(repo), path.string().c_str(), bare))
throw Error("creating Git repository '%s': %s", path, git_error_last()->message);
}
}
Expand Down Expand Up @@ -216,7 +216,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
std::vector<Submodule> parseSubmodules(const std::filesystem::path & configFile)
{
GitConfig config;
if (git_config_open_ondisk(Setter(config), configFile.c_str()))
if (git_config_open_ondisk(Setter(config), configFile.string().c_str()))
throw Error("parsing .gitmodules file: %s", git_error_last()->message);

ConfigIterator it;
Expand Down Expand Up @@ -288,7 +288,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>

/* Get submodule info. */
auto modulesFile = path / ".gitmodules";
if (pathExists(modulesFile))
if (pathExists(modulesFile.string()))
info.submodules = parseSubmodules(modulesFile);

return info;
Expand Down Expand Up @@ -377,10 +377,10 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
auto dir = this->path;
Strings gitArgs;
if (shallow) {
gitArgs = { "-C", dir, "fetch", "--quiet", "--force", "--depth", "1", "--", url, refspec };
gitArgs = { "-C", dir.string(), "fetch", "--quiet", "--force", "--depth", "1", "--", url, refspec };
}
else {
gitArgs = { "-C", dir, "fetch", "--quiet", "--force", "--", url, refspec };
gitArgs = { "-C", dir.string(), "fetch", "--quiet", "--force", "--", url, refspec };
}

runProgram(RunOptions {
Expand Down Expand Up @@ -426,7 +426,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
.args = {
"-c",
"gpg.ssh.allowedSignersFile=" + allowedSignersFile,
"-C", path,
"-C", path.string(),
"verify-commit",
rev.gitRev()
},
Expand Down
Loading

0 comments on commit ac253fb

Please sign in to comment.