Commit 77de547f by Nicolas Capens

Fix Mac OS library loading for unittests.

On Mac OS there is no rpath to set for the executable to locate libraries. Instead, dylibs themselves have an install_name which is the path where executables can load them from (added to the executable at link time). Bug swiftshader:68 Change-Id: Ia72eba0076ec83fc4492a5c118b4f5420d03a640 Reviewed-on: https://swiftshader-review.googlesource.com/10208Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent fda85a40
...@@ -59,7 +59,7 @@ void *loadLibrary(const char *(&names)[n], const char *mustContainSymbol = nullp ...@@ -59,7 +59,7 @@ void *loadLibrary(const char *(&names)[n], const char *mustContainSymbol = nullp
} }
} }
return 0; return nullptr;
} }
#if defined(_WIN32) #if defined(_WIN32)
...@@ -70,7 +70,7 @@ void *loadLibrary(const char *(&names)[n], const char *mustContainSymbol = nullp ...@@ -70,7 +70,7 @@ void *loadLibrary(const char *(&names)[n], const char *mustContainSymbol = nullp
inline void *getLibraryHandle(const char *path) inline void *getLibraryHandle(const char *path)
{ {
HMODULE module = 0; HMODULE module = NULL;
GetModuleHandleEx(0, path, &module); GetModuleHandleEx(0, path, &module);
return (void*)module; return (void*)module;
} }
...@@ -103,7 +103,7 @@ void *loadLibrary(const char *(&names)[n], const char *mustContainSymbol = nullp ...@@ -103,7 +103,7 @@ void *loadLibrary(const char *(&names)[n], const char *mustContainSymbol = nullp
return dlopen(path, RTLD_LAZY | RTLD_LOCAL); // Increment reference count return dlopen(path, RTLD_LAZY | RTLD_LOCAL); // Increment reference count
} }
return 0; return nullptr;
#endif #endif
} }
......
...@@ -43,10 +43,8 @@ config("swiftshader_libEGL_private_config") { ...@@ -43,10 +43,8 @@ config("swiftshader_libEGL_private_config") {
} }
shared_library("swiftshader_libEGL") { shared_library("swiftshader_libEGL") {
if (!is_mac) { output_name = "libEGL"
output_name = "libEGL" output_dir = "$root_out_dir/swiftshader"
output_dir = "$root_out_dir/swiftshader"
}
deps = [ deps = [
"//build/config:exe_and_shlib_deps", "//build/config:exe_and_shlib_deps",
...@@ -74,13 +72,12 @@ shared_library("swiftshader_libEGL") { ...@@ -74,13 +72,12 @@ shared_library("swiftshader_libEGL") {
"Quartz.framework", "Quartz.framework",
"Cocoa.framework", "Cocoa.framework",
] ]
ldflags = [ "-Wl,-install_name,@loader_path/swiftshader/libEGL.dylib" ]
} else if (is_win) { } else if (is_win) {
configs -= [ "//build/config/win:unicode" ] configs -= [ "//build/config/win:unicode" ]
ldflags = [ "/DEF:" + rebase_path("libGLESv2.def", root_build_dir) ] ldflags = [ "/DEF:" + rebase_path("libGLESv2.def", root_build_dir) ]
} else if (is_linux) { } else if (is_linux) {
sources += [ sources += [ "../../Main/libX11.cpp" ]
"../../Main/libX11.cpp",
]
ldflags = ldflags =
[ "-Wl,--version-script=" + rebase_path("exports.map", root_build_dir) ] [ "-Wl,--version-script=" + rebase_path("exports.map", root_build_dir) ]
} }
......
...@@ -55,16 +55,14 @@ config("swiftshader_libGLESv2_private_config") { ...@@ -55,16 +55,14 @@ config("swiftshader_libGLESv2_private_config") {
} }
shared_library("swiftshader_libGLESv2") { shared_library("swiftshader_libGLESv2") {
if (!is_mac) { output_name = "libGLESv2"
output_name = "libGLESv2" output_dir = "$root_out_dir/swiftshader"
output_dir = "$root_out_dir/swiftshader"
}
deps = [ deps = [
"//build/config:exe_and_shlib_deps",
"../../OpenGL/compiler:swiftshader_opengl_compiler", "../../OpenGL/compiler:swiftshader_opengl_compiler",
"../../Reactor:swiftshader_reactor", "../../Reactor:swiftshader_reactor",
"../../Renderer:swiftshader_renderer", "../../Renderer:swiftshader_renderer",
"//build/config:exe_and_shlib_deps",
] ]
sources = [ sources = [
...@@ -95,6 +93,8 @@ shared_library("swiftshader_libGLESv2") { ...@@ -95,6 +93,8 @@ shared_library("swiftshader_libGLESv2") {
if (is_win) { if (is_win) {
configs -= [ "//build/config/win:unicode" ] configs -= [ "//build/config/win:unicode" ]
ldflags = [ "/DEF:" + rebase_path("libGLESv2.def", root_build_dir) ] ldflags = [ "/DEF:" + rebase_path("libGLESv2.def", root_build_dir) ]
} else if (is_mac) {
ldflags = [ "-Wl,-install_name,@loader_path/swiftshader/libGLESv2.dylib" ]
} else if (is_linux) { } else if (is_linux) {
ldflags = ldflags =
[ "-Wl,--version-script=" + rebase_path("exports.map", root_build_dir) ] [ "-Wl,--version-script=" + rebase_path("exports.map", root_build_dir) ]
......
...@@ -16,12 +16,12 @@ import("//testing/test.gni") ...@@ -16,12 +16,12 @@ import("//testing/test.gni")
test("swiftshader_unittests") { test("swiftshader_unittests") {
deps = [ deps = [
"//third_party/swiftshader/src/OpenGL/libEGL:swiftshader_libEGL",
"//third_party/swiftshader/src/OpenGL/libGLESv2:swiftshader_libGLESv2",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//testing/gmock", "//testing/gmock",
"//testing/gtest", "//testing/gtest",
"//third_party/swiftshader/src/OpenGL/libEGL:swiftshader_libEGL",
"//third_party/swiftshader/src/OpenGL/libGLESv2:swiftshader_libGLESv2",
] ]
sources = [ sources = [
...@@ -29,13 +29,9 @@ test("swiftshader_unittests") { ...@@ -29,13 +29,9 @@ test("swiftshader_unittests") {
"unittests.cpp", "unittests.cpp",
] ]
include_dirs = [ include_dirs = [ "../../include" ] # Khronos headers
"../../include", # Khronos headers
]
defines = [ defines = [ "GL_GLEXT_PROTOTYPES" ]
"GL_GLEXT_PROTOTYPES",
]
# Make sure we're loading SwiftShader's libraries, not ANGLE's or the system # Make sure we're loading SwiftShader's libraries, not ANGLE's or the system
# provided ones. On Windows an explicit LoadLibrary("swiftshader\lib*.dll") # provided ones. On Windows an explicit LoadLibrary("swiftshader\lib*.dll")
...@@ -46,12 +42,9 @@ test("swiftshader_unittests") { ...@@ -46,12 +42,9 @@ test("swiftshader_unittests") {
"/DELAYLOAD:libGLESv2.dll", "/DELAYLOAD:libGLESv2.dll",
] ]
} else if (is_mac) { } else if (is_mac) {
ldflags = [ # On Mac OS the rpath is part of the dylib and a full file path instead of
"-Wl,-install_name,@rpath/\$ORIGIN/swiftshader", # a directory, which is added to the executable at link time.
]
} else { } else {
ldflags = [ ldflags = [ "-Wl,-rpath=\$ORIGIN/swiftshader" ]
"-Wl,-rpath=\$ORIGIN/swiftshader",
]
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment