Skip to content

Commit

Permalink
Merge pull request #74 from Faless/build/cache_and_paths
Browse files Browse the repository at this point in the history
[SCons] Fix caching and path detection.
  • Loading branch information
Faless authored Nov 28, 2022
2 parents 6067add + 2e9a25b commit 9715e73
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 28 deletions.
20 changes: 15 additions & 5 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ else:
ARGUMENTS["ios_min_version"] = "11.0"
env = SConscript("godot-cpp/SConstruct").Clone()

# Should probably go to upstream godot-cpp.
# We let SCons build its default ENV as it includes OS-specific things which we don't
# want to have to pull in manually.
# Then we prepend PATH to make it take precedence, while preserving SCons' own entries.
env.PrependENVPath("PATH", os.getenv("PATH"))
env.PrependENVPath("PKG_CONFIG_PATH", os.getenv("PKG_CONFIG_PATH"))
if "TERM" in os.environ: # Used for colored output.
env["ENV"]["TERM"] = os.environ["TERM"]

# Patch mingw SHLIBSUFFIX.
if env["platform"] == "windows" and env["use_mingw"]:
env["SHLIBSUFFIX"] = ".dll"
Expand All @@ -100,19 +109,20 @@ env.Append(BUILDERS={

# SSL
ssl = env.BuildOpenSSL(env.Dir(builders.get_ssl_build_dir(env)), env.Dir(builders.get_ssl_source_dir(env)))
env.Depends(ssl, env.File("builders.py"))
env.Depends(ssl, [env.File("builders.py"), env.File(builders.get_ssl_source_dir(env) + "/VERSION.dat")])
env.NoCache(ssl) # Needs refactoring to properly cache generated headers.

env.Prepend(CPPPATH=[builders.get_ssl_include_dir(env)])
env.Prepend(LIBPATH=[builders.get_ssl_build_dir(env)])
env.Append(LIBS=[ssl])
env.Append(LIBS=[builders.get_ssl_libs(env)])

# RTC
rtc = env.BuildLibDataChannel(env.Dir(builders.get_rtc_build_dir(env)), [env.Dir(builders.get_rtc_source_dir(env))] + ssl)
env.Depends(rtc, env.File("builders.py"))
env.Depends(rtc, [env.File("builders.py"), env.File(builders.get_rtc_source_dir(env) + "/CMakeLists.txt")])

env.Append(LIBPATH=[builders.get_rtc_build_dir(env)])
env.Append(CPPPATH=[builders.get_rtc_include_dir(env)])
env.Prepend(LIBS=[rtc])
env.Prepend(LIBS=[builders.get_rtc_libs(env)])

# Our includes and sources
env.Append(CPPPATH=["src/"])
Expand All @@ -130,7 +140,7 @@ else:
sources.append("src/init_gdnative.cpp")
add_sources(sources, "src/net/", "cpp")

env.Depends(sources, [ssl, rtc])
env.Depends(sources, [builders.get_ssl_libs(env), builders.get_rtc_libs(env)])

# Make the shared library
result_name = "webrtc_native{}{}".format(env["suffix"], env["SHLIBSUFFIX"])
Expand Down
53 changes: 30 additions & 23 deletions builders.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from SCons.Defaults import Mkdir
from SCons.Script import Environment


Expand Down Expand Up @@ -26,6 +27,17 @@ def get_rtc_include_dir(env):
return get_rtc_source_dir(env) + "/include"


def get_rtc_libs(env):
bdir = get_rtc_build_dir(env)
libs = [
"libdatachannel-static.a",
"deps/libjuice/libjuice-static.a",
"deps/libsrtp/libsrtp2.a",
"deps/usrsctp/usrsctplib/libusrsctp.a"
]
return [env.File(bdir + "/" + lib) for lib in libs]


def get_ssl_source_dir(env):
return get_deps_dir(env) + "/openssl"

Expand All @@ -42,19 +54,20 @@ def get_ssl_include_dir(env):
return get_ssl_install_dir(env) + "/include"


def get_ssl_libs(env):
bdir = get_ssl_build_dir(env)
return [env.File(bdir + "/" + lib) for lib in ["libssl.a", "libcrypto.a"]]


def ssl_emitter(target, source, env):
build_dir = get_ssl_build_dir(env)
libs = ["libssl.a", "libcrypto.a"]
install_dir = get_ssl_install_dir(env)
ssl_include = os.path.join(source[0].abspath, "include")
return [env.File(build_dir + "/" + l) for l in libs], source
return get_ssl_libs(env), source


def ssl_action(target, source, env):
build_dir = get_ssl_build_dir(env)
source_dir = source[0].abspath

ssl_env = Environment()
ssl_env = env.Clone()
install_dir = get_ssl_install_dir(env)
args = [
"no-ssl3",
Expand Down Expand Up @@ -126,8 +139,8 @@ def ssl_action(target, source, env):

jobs = env.GetOption("num_jobs")
ssl_env.Execute([
"mkdir -p " + build_dir, # TODO python?
("cd %s && %s/Configure " % (build_dir, source_dir)) + " ".join(args),
Mkdir(build_dir),
"cd %s && perl %s/Configure %s" % (build_dir, source_dir, " ".join(['"%s"' % a for a in args])),
"make -C %s -j%s" % (build_dir, jobs),
"make -C %s install_sw install_ssldirs -j%s" % (build_dir, jobs),
]
Expand All @@ -136,28 +149,20 @@ def ssl_action(target, source, env):


def rtc_emitter(target, source, env):
build_dir = get_rtc_build_dir(env)
libs = ["libdatachannel-static.a", "libjuice-static.a", "libsrtp2.a", "libusrsctp.a"]
lib_paths = [
build_dir,
os.path.join(build_dir, "deps/libjuice"),
os.path.join(build_dir, "deps/libsrtp"),
os.path.join(build_dir, "deps/usrsctp/usrsctplib"),
]
return [env.File(lib_paths[i] + "/" + libs[i]) for i in range(len(libs))], source
return get_rtc_libs(env), source


def rtc_action(target, source, env):
build_dir = get_rtc_build_dir(env)
source_dir = source[0].abspath
args = [
"cmake",
"-B",
build_dir,
"-DUSE_NICE=0",
"-DNO_WEBSOCKET=1",
#"-DNO_MEDIA=1", # Windows builds fail without it.
"-DNO_EXAMPLES=1",
"-DNO_WEBSOCKET=1",
"-DNO_TESTS=1",
"-DOPENSSL_USE_STATIC_LIBS=1",
"-DOPENSSL_INCLUDE_DIR=%s" % get_ssl_include_dir(env),
Expand Down Expand Up @@ -215,26 +220,28 @@ def rtc_action(target, source, env):
if env["arch"] == "x86_32":
if env["use_mingw"]:
args.extend([
"-G 'Unix Makefiles'",
"-G",
"Unix Makefiles",
"-DCMAKE_C_COMPILER=i686-w64-mingw32-gcc",
"-DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++",
"-DCMAKE_SYSTEM_NAME=Windows",
])
else:
if env["use_mingw"]:
args.extend([
"-G 'Unix Makefiles'",
"-G",
"Unix Makefiles",
"-DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc",
"-DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++",
"-DCMAKE_SYSTEM_NAME=Windows"
])

args.append(source_dir)
jobs = env.GetOption("num_jobs")
rtc_env = Environment()
rtc_env = env.Clone()
rtc_env.Execute([
"cmake " + " ".join(args),
"cmake --build %s -t datachannel-static -j%s" % (build_dir, jobs),
" ".join(['"%s"' % a for a in args]),
"cmake --build %s -t datachannel-static -j%s" % (build_dir, jobs)
]
)
return None

0 comments on commit 9715e73

Please sign in to comment.