From 194bd9e7f21ceba1cd59e395d0f5378facd61d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kita?= Date: Fri, 9 Feb 2024 15:24:14 +0100 Subject: [PATCH 1/8] Make the symlink to the directory with precompiled dependencies in priv/ creation not fail if the directory already exists --- lib/bundlex/toolchain/common/unix/os_deps.ex | 2 +- mix.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bundlex/toolchain/common/unix/os_deps.ex b/lib/bundlex/toolchain/common/unix/os_deps.ex index e2c0455..0abdf21 100644 --- a/lib/bundlex/toolchain/common/unix/os_deps.ex +++ b/lib/bundlex/toolchain/common/unix/os_deps.ex @@ -263,7 +263,7 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do unless File.exists?(symlink) do File.mkdir_p!(dir) - File.ln_s!(path_from_to(dir, target), symlink) + File.ln_s(path_from_to(dir, target), symlink) end :ok diff --git a/mix.exs b/mix.exs index 45fc73e..18fefa2 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Bundlex.Mixfile do use Mix.Project - @version "1.4.5" + @version "1.4.6" @github_url "https://github.com/membraneframework/bundlex" def project do From a91b1c273b9b50bb71929b6290c01c9a3438d020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kita?= Date: Mon, 12 Feb 2024 12:35:20 +0100 Subject: [PATCH 2/8] Add two relative links to rpath --- lib/bundlex/toolchain/common/unix/os_deps.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/bundlex/toolchain/common/unix/os_deps.ex b/lib/bundlex/toolchain/common/unix/os_deps.ex index 0abdf21..5fa46dd 100644 --- a/lib/bundlex/toolchain/common/unix/os_deps.ex +++ b/lib/bundlex/toolchain/common/unix/os_deps.ex @@ -134,7 +134,9 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do defp get_precompiled_libs_flags(dep_path, dep_dir_name, lib_names, native) do lib_path = Path.join(dep_path, "lib") output_path = Bundlex.Toolchain.output_path(native.app, native.interface) + dep_dir_name2 = dep_dir_name <> "2" create_relative_symlink(lib_path, output_path, dep_dir_name) + create_relative_symlink(lib_path, output_path, dep_dir_name2) # TODO: pass the platform via arguments # $ORIGIN must be escaped so that it's not treated as an ENV variable @@ -143,6 +145,7 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do [ "-L#{Path.join(dep_path, "lib")}", "-Wl,-rpath,#{rpath_root}/#{dep_dir_name}", + "-Wl,-rpath,#{rpath_root}/#{dep_dir_name2}", "-Wl,-rpath,/opt/homebrew/lib" ] ++ Enum.map(lib_names, &"-l#{remove_lib_prefix(&1)}") end @@ -262,7 +265,6 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do unless File.exists?(symlink) do File.mkdir_p!(dir) - File.ln_s(path_from_to(dir, target), symlink) end From 114e3c896411798e39cf97c1e6868c0d5e184eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kita?= Date: Mon, 12 Feb 2024 14:36:20 +0100 Subject: [PATCH 3/8] Create physical and logical symlink and add it to rpath --- lib/bundlex/toolchain/common/unix/os_deps.ex | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/bundlex/toolchain/common/unix/os_deps.ex b/lib/bundlex/toolchain/common/unix/os_deps.ex index 5fa46dd..d1740e3 100644 --- a/lib/bundlex/toolchain/common/unix/os_deps.ex +++ b/lib/bundlex/toolchain/common/unix/os_deps.ex @@ -131,12 +131,15 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do end end - defp get_precompiled_libs_flags(dep_path, dep_dir_name, lib_names, native) do - lib_path = Path.join(dep_path, "lib") + defp get_precompiled_libs_flags(dep_path, logical_dep_dir_name, lib_names, native) do + logical_lib_path = Path.join(dep_path, "lib") + {physical_lib_path, 0} = System.shell("realpath #{logical_lib_path}") + output_path = Bundlex.Toolchain.output_path(native.app, native.interface) - dep_dir_name2 = dep_dir_name <> "2" - create_relative_symlink(lib_path, output_path, dep_dir_name) - create_relative_symlink(lib_path, output_path, dep_dir_name2) + + physical_dep_dir_name = logical_dep_dir_name <> "_physical" + create_relative_symlink(logical_lib_path, output_path, logical_dep_dir_name) + create_relative_symlink(physical_lib_path, output_path, physical_dep_dir_name) # TODO: pass the platform via arguments # $ORIGIN must be escaped so that it's not treated as an ENV variable @@ -144,8 +147,8 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do [ "-L#{Path.join(dep_path, "lib")}", - "-Wl,-rpath,#{rpath_root}/#{dep_dir_name}", - "-Wl,-rpath,#{rpath_root}/#{dep_dir_name2}", + "-Wl,-rpath,#{rpath_root}/#{logical_dep_dir_name}", + "-Wl,-rpath,#{rpath_root}/#{physical_dep_dir_name}", "-Wl,-rpath,/opt/homebrew/lib" ] ++ Enum.map(lib_names, &"-l#{remove_lib_prefix(&1)}") end From 3aaa1a31d45b4a7666b371975f768657a2861747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kita?= Date: Mon, 12 Feb 2024 14:47:08 +0100 Subject: [PATCH 4/8] Add resolving of physical output path --- lib/bundlex/toolchain/common/unix/os_deps.ex | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/bundlex/toolchain/common/unix/os_deps.ex b/lib/bundlex/toolchain/common/unix/os_deps.ex index d1740e3..979da96 100644 --- a/lib/bundlex/toolchain/common/unix/os_deps.ex +++ b/lib/bundlex/toolchain/common/unix/os_deps.ex @@ -135,11 +135,12 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do logical_lib_path = Path.join(dep_path, "lib") {physical_lib_path, 0} = System.shell("realpath #{logical_lib_path}") - output_path = Bundlex.Toolchain.output_path(native.app, native.interface) + logical_output_path = Bundlex.Toolchain.output_path(native.app, native.interface) + {physical_output_path, 0} = System.shell("realpath #{logical_output_path}") physical_dep_dir_name = logical_dep_dir_name <> "_physical" - create_relative_symlink(logical_lib_path, output_path, logical_dep_dir_name) - create_relative_symlink(physical_lib_path, output_path, physical_dep_dir_name) + create_relative_symlink(logical_lib_path, logical_output_path, logical_dep_dir_name) + create_relative_symlink(physical_lib_path, physical_output_path, physical_dep_dir_name) # TODO: pass the platform via arguments # $ORIGIN must be escaped so that it's not treated as an ENV variable From 6efc5798a6f7ab626d0e0b56ff7f512149f338c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kita?= Date: Mon, 12 Feb 2024 14:53:11 +0100 Subject: [PATCH 5/8] fix a bug with a newline in the lib path --- lib/bundlex/toolchain/common/unix/os_deps.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/bundlex/toolchain/common/unix/os_deps.ex b/lib/bundlex/toolchain/common/unix/os_deps.ex index 979da96..10720f3 100644 --- a/lib/bundlex/toolchain/common/unix/os_deps.ex +++ b/lib/bundlex/toolchain/common/unix/os_deps.ex @@ -136,9 +136,12 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do {physical_lib_path, 0} = System.shell("realpath #{logical_lib_path}") logical_output_path = Bundlex.Toolchain.output_path(native.app, native.interface) - {physical_output_path, 0} = System.shell("realpath #{logical_output_path}") + # {physical_output_path, 0} = System.shell("realpath #{logical_output_path}") + physical_lib_path = String.slice(physical_lib_path, 0..-2) + physical_output_path = logical_output_path physical_dep_dir_name = logical_dep_dir_name <> "_physical" + create_relative_symlink(logical_lib_path, logical_output_path, logical_dep_dir_name) create_relative_symlink(physical_lib_path, physical_output_path, physical_dep_dir_name) From 611892d09a2351ff50b4b2afaf18b9c086b87524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kita?= Date: Mon, 12 Feb 2024 15:13:17 +0100 Subject: [PATCH 6/8] Use physical output path and logical output path in create_relative_symlink --- lib/bundlex/toolchain/common/unix/os_deps.ex | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/bundlex/toolchain/common/unix/os_deps.ex b/lib/bundlex/toolchain/common/unix/os_deps.ex index 10720f3..fb2ca70 100644 --- a/lib/bundlex/toolchain/common/unix/os_deps.ex +++ b/lib/bundlex/toolchain/common/unix/os_deps.ex @@ -132,18 +132,14 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do end defp get_precompiled_libs_flags(dep_path, logical_dep_dir_name, lib_names, native) do - logical_lib_path = Path.join(dep_path, "lib") - {physical_lib_path, 0} = System.shell("realpath #{logical_lib_path}") - + lib_path = Path.join(dep_path, "lib") logical_output_path = Bundlex.Toolchain.output_path(native.app, native.interface) - # {physical_output_path, 0} = System.shell("realpath #{logical_output_path}") + create_relative_symlink(lib_path, logical_output_path, logical_dep_dir_name) - physical_lib_path = String.slice(physical_lib_path, 0..-2) - physical_output_path = logical_output_path + {physical_output_path, 0} = System.shell("realpath #{logical_output_path}") + physical_output_path = String.slice(physical_output_path, 0..-2) physical_dep_dir_name = logical_dep_dir_name <> "_physical" - - create_relative_symlink(logical_lib_path, logical_output_path, logical_dep_dir_name) - create_relative_symlink(physical_lib_path, physical_output_path, physical_dep_dir_name) + create_relative_symlink(lib_path, physical_output_path, physical_dep_dir_name) # TODO: pass the platform via arguments # $ORIGIN must be escaped so that it's not treated as an ENV variable From 12ca92a2e097b9dadf3c90a0371a339cf764e54a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kita?= Date: Mon, 12 Feb 2024 15:18:04 +0100 Subject: [PATCH 7/8] Fix a warning with String.slice --- lib/bundlex/toolchain/common/unix/os_deps.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bundlex/toolchain/common/unix/os_deps.ex b/lib/bundlex/toolchain/common/unix/os_deps.ex index fb2ca70..1c25a33 100644 --- a/lib/bundlex/toolchain/common/unix/os_deps.ex +++ b/lib/bundlex/toolchain/common/unix/os_deps.ex @@ -137,7 +137,7 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do create_relative_symlink(lib_path, logical_output_path, logical_dep_dir_name) {physical_output_path, 0} = System.shell("realpath #{logical_output_path}") - physical_output_path = String.slice(physical_output_path, 0..-2) + physical_output_path = String.slice(physical_output_path, 0..-2//1) physical_dep_dir_name = logical_dep_dir_name <> "_physical" create_relative_symlink(lib_path, physical_output_path, physical_dep_dir_name) From 08eace5fe6d7317e65eaa4cb17c57bfb6dd4691b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kita?= Date: Mon, 12 Feb 2024 16:50:11 +0100 Subject: [PATCH 8/8] Implement reviewer's suggestions --- lib/bundlex/toolchain/common/unix/os_deps.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/bundlex/toolchain/common/unix/os_deps.ex b/lib/bundlex/toolchain/common/unix/os_deps.ex index 1c25a33..060c9c4 100644 --- a/lib/bundlex/toolchain/common/unix/os_deps.ex +++ b/lib/bundlex/toolchain/common/unix/os_deps.ex @@ -136,8 +136,12 @@ defmodule Bundlex.Toolchain.Common.Unix.OSDeps do logical_output_path = Bundlex.Toolchain.output_path(native.app, native.interface) create_relative_symlink(lib_path, logical_output_path, logical_dep_dir_name) + # We create a second ("physical") symlink to the place where the precompiled dependencies + # are stored because we need to assure that the relative link in the symlink's target + # will work properly also when the symlink is put in the location, for which the + # logical path differs from the physical path {physical_output_path, 0} = System.shell("realpath #{logical_output_path}") - physical_output_path = String.slice(physical_output_path, 0..-2//1) + physical_output_path = String.trim_trailing(physical_output_path) physical_dep_dir_name = logical_dep_dir_name <> "_physical" create_relative_symlink(lib_path, physical_output_path, physical_dep_dir_name)