Skip to content

Commit

Permalink
Build libnixutil with MinGW
Browse files Browse the repository at this point in the history
Co-Authored-By volth <[email protected]>
  • Loading branch information
Ericson2314 committed Nov 9, 2023
1 parent 7592f6e commit 1ff607e
Show file tree
Hide file tree
Showing 53 changed files with 1,217 additions and 830 deletions.
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
-include Makefile.config
clean-files += Makefile.config

include mk/platform.mk

ifeq ($(ENABLE_BUILD), yes)
makefiles = \
mk/precompiled-headers.mk \
local.mk \
src/libutil/local.mk \
src/libutil/local.mk

ifdef HOST_UNIX
makefiles += \
src/libstore/local.mk \
src/libfetchers/local.mk \
src/libmain/local.mk \
Expand All @@ -23,22 +28,28 @@ makefiles = \
doc/manual/local.mk \
doc/internal-api/local.mk
endif
endif

ifeq ($(ENABLE_BUILD)_$(ENABLE_TESTS), yes_yes)
UNIT_TEST_ENV = _NIX_TEST_UNIT_DATA=unit-test-data
makefiles += \
src/libutil/tests/local.mk \
src/libutil/tests/local.mk
ifdef HOST_UNIX
makefiles += \
src/libstore/tests/local.mk \
src/libexpr/tests/local.mk
endif
endif

ifeq ($(ENABLE_TESTS), yes)
ifdef HOST_UNIX
makefiles += \
tests/functional/local.mk \
tests/functional/ca/local.mk \
tests/functional/dyn-drv/local.mk \
tests/functional/test-libstoreconsumer/local.mk \
tests/functional/plugins/local.mk
endif
else
makefiles += \
mk/disable-tests.mk
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
33 changes: 1 addition & 32 deletions mk/lib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,7 @@ man-pages :=
install-tests :=
install-tests-groups :=

ifdef HOST_OS
HOST_KERNEL = $(firstword $(subst -, ,$(HOST_OS)))
ifeq ($(patsubst mingw%,,$(HOST_KERNEL)),)
HOST_MINGW = 1
HOST_WINDOWS = 1
endif
ifeq ($(HOST_KERNEL), cygwin)
HOST_CYGWIN = 1
HOST_WINDOWS = 1
HOST_UNIX = 1
endif
ifeq ($(patsubst darwin%,,$(HOST_KERNEL)),)
HOST_DARWIN = 1
HOST_UNIX = 1
endif
ifeq ($(patsubst freebsd%,,$(HOST_KERNEL)),)
HOST_FREEBSD = 1
HOST_UNIX = 1
endif
ifeq ($(patsubst netbsd%,,$(HOST_KERNEL)),)
HOST_NETBSD = 1
HOST_UNIX = 1
endif
ifeq ($(HOST_KERNEL), linux)
HOST_LINUX = 1
HOST_UNIX = 1
endif
ifeq ($(patsubst solaris%,,$(HOST_KERNEL)),)
HOST_SOLARIS = 1
HOST_UNIX = 1
endif
endif
include mk/platform.mk

# Hack to define a literal space.
space :=
Expand Down
6 changes: 3 additions & 3 deletions mk/libraries.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ libs-list :=
ifdef HOST_DARWIN
SO_EXT = dylib
else
ifdef HOST_CYGWIN
ifdef HOST_WINDOWS
SO_EXT = dll
else
SO_EXT = so
Expand Down Expand Up @@ -59,7 +59,7 @@ define build-library
$(1)_OBJS := $$(addprefix $(buildprefix), $$(addsuffix .o, $$(basename $$(_srcs))))
_libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH))

ifdef HOST_CYGWIN
ifdef HOST_WINDOWS
$(1)_INSTALL_DIR ?= $$(bindir)
else
$(1)_INSTALL_DIR ?= $$(libdir)
Expand All @@ -79,7 +79,7 @@ define build-library
endif
else
ifndef HOST_DARWIN
ifndef HOST_CYGWIN
ifndef HOST_WINDOWS
$(1)_LDFLAGS += -Wl,-z,defs
endif
endif
Expand Down
32 changes: 32 additions & 0 deletions mk/platform.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ifdef HOST_OS
HOST_KERNEL = $(firstword $(subst -, ,$(HOST_OS)))
ifeq ($(patsubst mingw%,,$(HOST_KERNEL)),)
HOST_MINGW = 1
HOST_WINDOWS = 1
endif
ifeq ($(HOST_KERNEL), cygwin)
HOST_CYGWIN = 1
HOST_WINDOWS = 1
HOST_UNIX = 1
endif
ifeq ($(patsubst darwin%,,$(HOST_KERNEL)),)
HOST_DARWIN = 1
HOST_UNIX = 1
endif
ifeq ($(patsubst freebsd%,,$(HOST_KERNEL)),)
HOST_FREEBSD = 1
HOST_UNIX = 1
endif
ifeq ($(patsubst netbsd%,,$(HOST_KERNEL)),)
HOST_NETBSD = 1
HOST_UNIX = 1
endif
ifeq ($(HOST_KERNEL), linux)
HOST_LINUX = 1
HOST_UNIX = 1
endif
ifeq ($(patsubst solaris%,,$(HOST_KERNEL)),)
HOST_SOLARIS = 1
HOST_UNIX = 1
endif
endif
10 changes: 8 additions & 2 deletions mk/programs.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
programs-list :=

ifdef HOST_WINDOWS
EXE_EXT = .exe
else
EXE_EXT =
endif

# Build a program with symbolic name $(1). The program is defined by
# various variables prefixed by ‘$(1)_’:
#
Expand Down Expand Up @@ -31,7 +37,7 @@ define build-program
_srcs := $$(sort $$(foreach src, $$($(1)_SOURCES), $$(src)))
$(1)_OBJS := $$(addprefix $(buildprefix), $$(addsuffix .o, $$(basename $$(_srcs))))
_libs := $$(foreach lib, $$($(1)_LIBS), $$(foreach lib2, $$($$(lib)_LIB_CLOSURE), $$($$(lib2)_PATH)))
$(1)_PATH := $$(_d)/$$($(1)_NAME)
$(1)_PATH := $$(_d)/$$($(1)_NAME)$(EXE_EXT)

$$(eval $$(call create-dir, $$(_d)))

Expand All @@ -42,7 +48,7 @@ define build-program

ifdef $(1)_INSTALL_DIR

$(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$$($(1)_NAME)
$(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$$($(1)_NAME)$(EXE_EXT)

$$(eval $$(call create-dir, $$($(1)_INSTALL_DIR)))

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>
8 changes: 8 additions & 0 deletions src/libutil/archive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
#include "file-system.hh"
#include "signals.hh"

#if _WIN32
# include <fileapi.h>
# include "windows-file-path.hh"
# include "windows-error.hh"
#endif

namespace nix {

struct ArchiveSettings : Config
Expand Down Expand Up @@ -212,11 +218,13 @@ static void parse(ParseSink & sink, Source & source, const Path & path)
sink.closeRegularFile();
}

#ifndef _WIN32
else if (s == "executable" && type == tpRegular) {
auto s = readString(source);
if (s != "") throw badArchive("executable marker has non-empty value");
sink.isExecutable();
}
#endif

else if (s == "entry" && type == tpDirectory) {
std::string name, prevName;
Expand Down
8 changes: 6 additions & 2 deletions src/libutil/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include <fstream>
#include <string>
#include <regex>
#include <glob.h>
#ifndef _WIN32
# include <glob.h>
#endif

namespace nix {

Expand Down Expand Up @@ -481,7 +483,7 @@ bool Args::processArgs(const Strings & args, bool finish)
if (!anyCompleted)
exp.handler.fun(ss);

/* Move the list element to the processedArgs. This is almost the same as
/* Move the list element to the processedArgs. This is almost the same as
`processedArgs.push_back(expectedArgs.front()); expectedArgs.pop_front()`,
except that it will only adjust the next and prev pointers of the list
elements, meaning the actual contents don't move in memory. This is
Expand Down Expand Up @@ -578,6 +580,7 @@ Args::Flag Args::Flag::mkHashTypeOptFlag(std::string && longName, std::optional<
static void _completePath(AddCompletions & completions, std::string_view prefix, bool onlyDirs)
{
completions.setType(Completions::Type::Filenames);
#ifndef _WIN32
glob_t globbuf;
int flags = GLOB_NOESCAPE;
#ifdef GLOB_ONLYDIR
Expand All @@ -595,6 +598,7 @@ static void _completePath(AddCompletions & completions, std::string_view prefix,
}
}
globfree(&globbuf);
#endif
}

void Args::completePath(AddCompletions & completions, size_t, std::string_view prefix)
Expand Down
10 changes: 8 additions & 2 deletions src/libutil/current-process.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "current-process.hh"
#include "namespaces.hh"
#include "util.hh"
#include "finally.hh"
#include "file-system.hh"
Expand All @@ -14,9 +13,12 @@
# include <mutex>
# include <sys/resource.h>
# include "cgroup.hh"
# include "namespaces.hh"
#endif

#include <sys/mount.h>
#ifndef _WIN32
# include <sys/mount.h>
#endif

namespace nix {

Expand Down Expand Up @@ -67,9 +69,13 @@ void setStackSize(size_t stackSize)

void restoreProcessContext(bool restoreMounts)
{
#ifndef _WIN32
restoreSignals();
#endif
if (restoreMounts) {
#if __linux__
restoreMountNamespace();
#endif
}

#if __linux__
Expand Down
14 changes: 0 additions & 14 deletions src/libutil/environment-variables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,4 @@ std::map<std::string, std::string> getEnv()
return env;
}


void clearEnv()
{
for (auto & name : getEnv())
unsetenv(name.first.c_str());
}

void replaceEnv(const std::map<std::string, std::string> & newEnv)
{
clearEnv();
for (auto & newEnvVar : newEnv)
setenv(newEnvVar.first.c_str(), newEnvVar.second.c_str(), 1);
}

}
2 changes: 1 addition & 1 deletion src/libutil/error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void BaseError::addTrace(std::shared_ptr<AbstractPos> && e, hintformat hint, boo

void throwExceptionSelfCheck(){
// This is meant to be caught in initLibUtil()
throw SysError("C++ exception handling is broken. This would appear to be a problem with the way Nix was compiled and/or linked and/or loaded.");
throw Error("C++ exception handling is broken. This would appear to be a problem with the way Nix was compiled and/or linked and/or loaded.");
}

// c++ std::exception descendants must have a 'const char* what()' function.
Expand Down
Loading

0 comments on commit 1ff607e

Please sign in to comment.