diff --git a/local-remote-execution/lre-mojo.nix b/local-remote-execution/lre-mojo.nix index 487c63e..dd68e27 100644 --- a/local-remote-execution/lre-mojo.nix +++ b/local-remote-execution/lre-mojo.nix @@ -5,24 +5,7 @@ }: let - # This environment is shared between toolchain autogen images and the final - # toolchain image. Env = mojoEnv; - # [ - # # Add all tooling here so that the generated toolchains use `/nix/store/*` - # # paths instead of `/bin` or `/usr/bin`. This way we're guaranteed to use - # # binary identical toolchains during local and remote execution. - # ("PATH=" - # + (lib.strings.concatStringsSep ":" [ - # "${gcc}/bin" - # "${mojo-sdk}/bin" - # ])) - # "MODULAR_HOME=${mojo-sdk}" - # "MOJO_COMPILER=${mojo-sdk}/bin/mojo" - # "MOJO_CC_PATH=${gcc}/bin:${mojo-sdk}/bin" - # "MOJO_LIBRARY_PATH=${zlib}/lib:${ncurses}/lib" - # "MOJO_PYTHON_LIBRARY=${python312}/lib" - # ]; in buildImage { name = "lre-mojo"; diff --git a/modules/defaultMojoEnv.nix b/modules/defaultMojoEnv.nix index d3abb0d..65d6158 100644 --- a/modules/defaultMojoEnv.nix +++ b/modules/defaultMojoEnv.nix @@ -1,16 +1,11 @@ { pkgs, mojo-sdk, ... }: [ - # "PATH=${pkgs.lib.makeBinPath mojo-sdk.passthru.mojoBinPath}" "MODULAR_HOME=${mojo-sdk}" "MOJO_COMPILER=${mojo-sdk}/bin/mojo" "MOJO_CC_PATH=${pkgs.lib.makeBinPath mojo-sdk.passthru.mojoBinPath}" - "MOJO_LIBRARY_PATH=${pkgs.lib.makeLibraryPath mojo-sdk.passthru.mojoLibraryPath}" "LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath mojo-sdk.passthru.mojoLibraryPath}" - # "MOJO_LIBRARY_PATH=${pkgs.zlib-ng.override{withZlibCompat=true;}}/lib:${pkgs.ncurses}/lib" - - # TODO(aaronmondal): This needs to be set during runtime. Let's just add it to - # a mojo wrapper script. + # TODO(aaronmondal): This needs to be set during runtime. # "MOJO_PYTHON_LIBRARY=${pkgs.python312}/lib/libpython3.12.so.1.0" ] diff --git a/mojo-sdk.nix b/mojo-sdk.nix index 18827af..375f51d 100644 --- a/mojo-sdk.nix +++ b/mojo-sdk.nix @@ -50,8 +50,6 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ autoPatchelfHook zstd makeWrapper ]; - # nativeBuildInputs = [ autoPatchelfHook zstd makeWrapper ]; - unpackPhase = '' zstd -d $src -c | tar xvf - ''; @@ -61,11 +59,6 @@ stdenv.mkDerivation rec { # that is `libedit.so.2.0.72` in Ubuntu. ln -s ${libedit}/lib/libedit.so.0 lib/libedit.so.2 - # Brute-force copy tinfo into the same directory as the mojo sources. - # It appears that mojo can't figure out how to find libtinfo otherwise. - cp ${tinfo}/lib/libtinfo.so.6.4 lib/libtinfo.so.6.4 - ln -s libtinfo.so.6.4 lib/libtinfo.so.6 - # The mojo command uses this config file to determine the # locations to bundled dependencies. Remap it to /nix/store. sed -i "s|\$_self.install_path|$out|g" modular.cfg @@ -87,9 +80,8 @@ stdenv.mkDerivation rec { # # WARNING: At the moment linking phase can't figure out how to link tinfo. # To work around this we allow leaving the tinfo symbols undefined and - # unlinked. This is a very risky and dangerous practice that might trigger - # random segfaults during runtime. - sed -i "s|system_libs = -lrt,-ldl,-lpthread,-lm,-lz,-ltinfo;|system_libs = -fuse-ld=mold,-lrt,-ldl,-lpthread,-lm,-L,${zlib}/lib,-Xlinker,-rpath=${zlib}/lib,-Xlinker,-L,${tinfo}/lib,-Xlinker,-rpath=${tinfo}/lib,-Xlinker,-rpath=${stdenv.cc.cc.lib}/lib,--verbose,-Xlinker,--verbose,-Xlinker,-v,-Xlinker,--allow-shlib-undefined,-Xlinker,--unresolved-symbols=ignore-all;|g" modular.cfg + # unlinked. This is a risky practice and might trigger segfaults at runtime. + sed -i "s|system_libs = -lrt,-ldl,-lpthread,-lm,-lz,-ltinfo;|system_libs = -fuse-ld=mold,-lrt,-ldl,-lpthread,-lm,-Xlinker,-rpath=${glibc}/lib,-L,${zlib}/lib,-Xlinker,-rpath=${zlib}/lib,-Xlinker,-L,${tinfo}/lib,-Xlinker,-rpath=${tinfo}/lib,-Xlinker,-rpath=${stdenv.cc.cc.lib}/lib,-Xlinker,--unresolved-symbols=ignore-in-object-files,--verbose;|g" modular.cfg ''; installPhase = '' @@ -108,11 +100,9 @@ stdenv.mkDerivation rec { postInstall = '' wrap_with_env() { wrapProgram $1 \ + --set MODULAR_HOME $out \ --prefix PATH : ${clang}/bin:${mold}/bin:${uutils-coreutils-noprefix}/bin \ - --prefix MODULAR_HOME : $out \ - --prefix LIBRARY_PATH : ${makeLibraryPath [ tinfo ncurses zlib stdenv.cc.cc.lib ]} \ - --prefix LD_LIBRARY_PATH : ${makeLibraryPath [ tinfo ncurses zlib stdenv.cc.cc.lib ]} \ - --set LD_LIBRARY_PATH ${makeLibraryPath [ tinfo ncurses zlib stdenv.cc.cc.lib ]} + --prefix LD_LIBRARY_PATH : ${makeLibraryPath [ tinfo ncurses zlib stdenv.cc.cc.lib glibc ]} } wrap_with_env $out/bin/mojo diff --git a/mojo/BUILD.bazel b/mojo/BUILD.bazel index c1ec2e7..00ece45 100644 --- a/mojo/BUILD.bazel +++ b/mojo/BUILD.bazel @@ -13,10 +13,8 @@ load("//mojo:toolchain.bzl", "mojo_toolchain") "MODULAR_HOME", "MOJO_COMPILER", "MOJO_CC_PATH", - "MOJO_LIBRARY_PATH", - "MOJO_PYTHON_LIBRARY", "LD_LIBRARY_PATH", - "MOJO_DYNAMIC_LINKER", + "MOJO_PYTHON_LIBRARY", # Unset values default to an empty string. "MOJO_UNSET", @@ -27,10 +25,10 @@ toolchain_type(name = "toolchain_type") mojo_toolchain( name = "mojo_toolchain_x86_64-unknown-linux-gnu", + LD_LIBRARY_PATH = ":LD_LIBRARY_PATH", MODULAR_HOME = ":MODULAR_HOME", MOJO_CC_PATH = ":MOJO_CC_PATH", MOJO_COMPILER = ":MOJO_COMPILER", - MOJO_LIBRARY_PATH = ":MOJO_LIBRARY_PATH", MOJO_PYTHON_LIBRARY = ":MOJO_PYTHON_LIBRARY", visibility = ["//visibility:public"], ) diff --git a/mojo/mojo.bzl b/mojo/mojo.bzl index 6b2c275..4118ba2 100644 --- a/mojo/mojo.bzl +++ b/mojo/mojo.bzl @@ -129,12 +129,7 @@ def _mojo_library_impl(ctx): tools = [toolchain.symbolizer], use_default_shell_env = False, env = { - # "PATH": toolchain.MOJO_CC_PATH, - # "MODULAR_HOME": toolchain.MODULAR_HOME, - # "LIBRARY_PATH": toolchain.MOJO_LIBRARY_PATH, - # "MOJO_PYTHON_LIBRARY": toolchain.MOJO_PYTHON_LIBRARY, - # "LLVM_SYMBOLIZER_PATH": toolchain.symbolizer.path, - # "LD_LIBRARY_PATH": toolchain.MOJO_LIBRARY_PATH, + "LLVM_SYMBOLIZER_PATH": toolchain.symbolizer.path, }, ) @@ -199,12 +194,7 @@ def _mojo_binary_impl(ctx): tools = [toolchain.symbolizer], use_default_shell_env = False, env = { - # "MODULAR_HOME": toolchain.MODULAR_HOME, - # "PATH": toolchain.MOJO_CC_PATH, - # "LIBRARY_PATH": toolchain.MOJO_LIBRARY_PATH, - # "LD_LIBRARY_PATH": toolchain.MOJO_LIBRARY_PATH, - # "MOJO_PYTHON_LIBRARY": toolchain.MOJO_PYTHON_LIBRARY, - # "LLVM_SYMBOLIZER_PATH": toolchain.symbolizer.path, + "LLVM_SYMBOLIZER_PATH": toolchain.symbolizer.path, }, ) diff --git a/mojo/toolchain.bzl b/mojo/toolchain.bzl index e2aa0c7..ba7f8aa 100644 --- a/mojo/toolchain.bzl +++ b/mojo/toolchain.bzl @@ -11,7 +11,7 @@ def _mojo_toolchain_impl(ctx): MODULAR_HOME = ctx.attr.MODULAR_HOME[BuildSettingInfo].value, MOJO_COMPILER = ctx.attr.MOJO_COMPILER[BuildSettingInfo].value, MOJO_CC_PATH = ctx.attr.MOJO_CC_PATH[BuildSettingInfo].value, - MOJO_LIBRARY_PATH = ctx.attr.MOJO_LIBRARY_PATH[BuildSettingInfo].value, + LD_LIBRARY_PATH = ctx.attr.LD_LIBRARY_PATH[BuildSettingInfo].value, MOJO_PYTHON_LIBRARY = ctx.attr.MOJO_PYTHON_LIBRARY[BuildSettingInfo].value, symbolizer = ctx.executable.symbolizer, ), @@ -29,7 +29,7 @@ mojo_toolchain = rule( doc = "The path to the mojo compiler.", ), "MOJO_CC_PATH": attr.label(), - "MOJO_LIBRARY_PATH": attr.label(), + "LD_LIBRARY_PATH": attr.label(), "MOJO_PYTHON_LIBRARY": attr.label(), "symbolizer": attr.label( doc = "The `llvm-symbolizer`.",