Skip to content

Commit

Permalink
Fix weird NixOS behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikMcClure committed Dec 24, 2022
1 parent 01c2d4b commit 8888da4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ For those building from source on Windows, we use a [vcpkg fork](https://github.


### Linux
Since inNative requires C++17 to build, the minimum supported compiler is gcc-7 or clang-5. Either use the provided nix flake to build via nix, or install LLVM 13 and Python from your package manager. Then run `cmake` to create makefiles or a Ninja configuration that you can then use to build the project. It is suggested to create a new folder called `build` and then run `cmake ..` to isolate the generated project files.
Since inNative requires C++17 to build, the minimum supported compiler is gcc-7 or clang-5. Either use the provided nix flake to build via nix by running `nix build .?submodules=1`, or install LLVM 13 and Python from your package manager. Then run `cmake` to create makefiles or a Ninja configuration that you can then use to build the project. It is suggested to create a new folder called `build` and then run `cmake ..` to isolate the generated project files.

## Targeting inNative
To build a shared library that does not rely on WASI, you can use `wasm_malloc.c` and clang:
Expand Down
2 changes: 2 additions & 0 deletions innative-test/test_assemblyscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void TestHarness::test_assemblyscript()
if(assembly)
(*_exports.FreeAssembly)(assembly);

printf("%s\n", dll_path.string().c_str());
remove(dll_path);
};

Expand All @@ -118,6 +119,7 @@ void TestHarness::test_assemblyscript()
embedpath.resize((*_exports.GetEmbeddingPath)(CURRENT_ABI, CURRENT_ARCH, false, TEST_EMBEDDING, nullptr, 0));
embedpath.resize(
(*_exports.GetEmbeddingPath)(CURRENT_ABI, CURRENT_ARCH, false, TEST_EMBEDDING, embedpath.data(), embedpath.capacity()));

size_t embedsz = 0;
auto embedfile = utility::LoadFile(embedpath, embedsz);

Expand Down
2 changes: 2 additions & 0 deletions innative/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ void innative_set_work_dir_to_bin(const char* arg0)
utility::SetWorkingDir(utility::GetProgramPath(arg0).parent_path().u8string().c_str());
}

#ifdef IN_PLATFORM_WIN32
int innative_install(const char* arg0, bool full) { return utility::Install(arg0, full); }

int innative_uninstall() { return utility::Uninstall(); }
#endif
9 changes: 6 additions & 3 deletions innative/link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,12 @@ void innative::DeleteCache(const Environment& env, Module& m)
{
// Certain error conditions can result in us clearing the cache of an invalid module.
if(m.name.size() > 0) // Prevent an error from happening if the name is invalid.
remove(GetLinkerObjectPath(env, m, path(),
env.abi == IN_ABI_Windows ? LLD_FORMAT::COFF :
LLD_FORMAT::ELF)); // Always remove the file if it exists
{
auto file = GetLinkerObjectPath(env, m, path(), env.abi == IN_ABI_Windows ? LLD_FORMAT::COFF : LLD_FORMAT::ELF);

if(exists(file)) // Only remove the file if it exists, otherwise NixOS gives us a brain-dead error message of "read only file system"
remove(file);
}

if(m.cache != nullptr)
{
Expand Down
21 changes: 20 additions & 1 deletion innative/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <stdio.h>
#include <sstream>
#include <stdarg.h>
#include <string.h>

#ifdef IN_COMPILER_MSC
#pragma warning(disable : 4062)
Expand Down Expand Up @@ -333,7 +334,25 @@ IN_ERROR innative::FinalizeEnvironment(Environment* env)
f = testpath(f, src, out);
f = testpath(f, rootpath / src, out);


#ifndef IN_PLATFORM_WIN32
// TODO: getenv("LD_LIBRARY_PATH")

if(GetArchBits(env->arch) == 64)
f = testpath(f, rootpath.parent_path() / "lib64" / platform / src, out);
f = testpath(f, rootpath.parent_path() / "lib" / platform / src, out);

if(GetArchBits(env->arch) == 64)
f = testpath(f, path("/usr/lib64/") / platform / src, out);
f = testpath(f, path("/usr/lib/") / platform / src, out);
f = testpath(f, path("../") / "lib" / platform / src, out);

src = "lib" + src.string();
f = testpath(f, envpath / src, out);
f = testpath(f, envpath / platform / src, out);
f = testpath(f, src, out);
f = testpath(f, rootpath / src, out);

if(GetArchBits(env->arch) == 64)
f = testpath(f, rootpath.parent_path() / "lib64" / platform / src, out);
f = testpath(f, rootpath.parent_path() / "lib" / platform / src, out);
Expand All @@ -345,7 +364,7 @@ IN_ERROR innative::FinalizeEnvironment(Environment* env)
#endif

if(!f)
return LogErrorString(*env, "%s: Error loading file: %s", ERR_FATAL_FILE_ERROR, embed->name,
return LogErrorString(*env, "%s: Error loading file: %s %s", ERR_FATAL_FILE_ERROR, embed->name,
src.u8string().c_str());
fclose(f);

Expand Down

0 comments on commit 8888da4

Please sign in to comment.