From 26220ccd933988a9431510f68fe8d18c136d7710 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Fri, 5 May 2023 20:11:32 -0500 Subject: [PATCH 1/7] add support for freebsd * Add support for the FreeBSD platform and the freebsd-64 subdir. * The platform uses .so extensions, elffiles, and defaults to a clang toolchain. * Add a freebsd selector and include the freebsd platform in the unix selector. --- conda_build/environ.py | 2 ++ conda_build/metadata.py | 2 +- conda_build/post.py | 1 + conda_build/variants.py | 5 +++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/conda_build/environ.py b/conda_build/environ.py index 5afcf93c4d..d067c68257 100644 --- a/conda_build/environ.py +++ b/conda_build/environ.py @@ -583,6 +583,8 @@ def get_shlib_ext(host_platform): return ".dylib" elif host_platform.startswith("linux") or host_platform.endswith("-wasm32"): return ".so" + elif host_platform.startswith("freebsd"): + return ".so" elif host_platform == "noarch": # noarch packages should not contain shared libraries, use the system # platform if this is requested diff --git a/conda_build/metadata.py b/conda_build/metadata.py index d2d87912bf..66adb23328 100644 --- a/conda_build/metadata.py +++ b/conda_build/metadata.py @@ -125,7 +125,7 @@ def get_selectors(config: Config) -> dict[str, bool]: linux32=bool(plat == "linux-32"), linux64=bool(plat == "linux-64"), arm=plat.startswith("linux-arm"), - unix=plat.startswith(("linux-", "osx-", "emscripten-")), + unix=plat.startswith(("linux-", "osx-", "emscripten-", "freebsd-")), win32=bool(plat == "win-32"), win64=bool(plat == "win-64"), os=os, diff --git a/conda_build/post.py b/conda_build/post.py index 290779385d..1ff8901043 100644 --- a/conda_build/post.py +++ b/conda_build/post.py @@ -59,6 +59,7 @@ "win": ("DLLfile", "EXEfile"), "osx": ["machofile"], "linux": ["elffile"], + "freebsd": ["elffile"], } diff --git a/conda_build/variants.py b/conda_build/variants.py index d7c6841238..ba968ba4cb 100644 --- a/conda_build/variants.py +++ b/conda_build/variants.py @@ -78,6 +78,11 @@ "cxx": "clangxx", "fortran": "gfortran", }, + "freebsd": { + "c": "clang", + "cxx": "clangxx", + "fortran": "gfortran", + }, } arch_name = subdir.rsplit("-", 1)[-1] From 45139e57f2f15d44b4402a7cacb8fa052bec37e6 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Fri, 5 May 2023 20:16:00 -0500 Subject: [PATCH 2/7] use the POSIX-standard . to execute commands Use the portable and POSIX-standard '.' to execute commands in scripts on non-Windows platforms rather than the non-portable 'source' command. Note that on FreeBSD, source is not provided by the default install or shell. --- conda_build/build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conda_build/build.py b/conda_build/build.py index 1d66cf114f..41fee4eff3 100644 --- a/conda_build/build.py +++ b/conda_build/build.py @@ -3205,7 +3205,7 @@ def write_build_scripts(m, script, build_file): with open(work_file, "w") as bf: # bf.write('set -ex\n') bf.write("if [ -z ${CONDA_BUILD+x} ]; then\n") - bf.write(f" source {env_file}\n") + bf.write(f" . {env_file}\n") bf.write("fi\n") if script: bf.write(script) @@ -3231,7 +3231,7 @@ def _write_test_run_script( with open(test_run_script, "w") as tf: tf.write( '{source} "{test_env_script}"\n'.format( - source="call" if utils.on_win else "source", + source="call" if utils.on_win else ".", test_env_script=test_env_script, ) ) From ca1cbdd40231401d2113f3b7cd6739b22b7323e2 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Fri, 5 May 2023 20:16:34 -0500 Subject: [PATCH 3/7] use a more portable no backup argument to patch Use the --posix argument to prevent patch from making backup files rather than the --no-backup-if-mismatch argument which is specific to GNU patch and not supported by various *BSD implementations. --- conda_build/source.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conda_build/source.py b/conda_build/source.py index c8d21a4c2e..fcc59ee499 100644 --- a/conda_build/source.py +++ b/conda_build/source.py @@ -934,7 +934,7 @@ def try_apply_patch(patch, patch_args, cwd, stdout, stderr): temp_name = os.path.join( tempfile.gettempdir(), next(tempfile._get_candidate_names()) ) - base_patch_args = ["--no-backup-if-mismatch", "--batch"] + patch_args + base_patch_args = ["--posix", "--batch"] + patch_args try: try_patch_args = base_patch_args[:] try_patch_args.append("--dry-run") From cbf775aa33236141b605f2912da22da00934cda8 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Fri, 5 May 2023 20:16:45 -0500 Subject: [PATCH 4/7] use bash rather than sh on bsd Many conda recipe build files use shell syntax and commands that are specific to bash and not POSIX shells. Given the large number of these that occur it is easier run the build script in bash than convert them. On Linux and macOS, bash is already used explicitly. On FreeBSD, bash is not part of the base system and must be installed via ports. The install location is /usr/local/bin/bash. --- conda_build/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conda_build/build.py b/conda_build/build.py index 41fee4eff3..108807b0bd 100644 --- a/conda_build/build.py +++ b/conda_build/build.py @@ -94,7 +94,7 @@ import conda_build.windows as windows if "bsd" in sys.platform: - shell_path = "/bin/sh" + shell_path = "/usr/local/bin/bash" elif utils.on_win: shell_path = "bash" else: From 43b415664fb1fef7171711fc09dee4e2435eb20e Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Fri, 5 May 2023 20:40:56 -0500 Subject: [PATCH 5/7] document freebsd and unix selectors --- docs/source/resources/define-metadata.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/source/resources/define-metadata.rst b/docs/source/resources/define-metadata.rst index c9e1ddd32b..633ce55d36 100644 --- a/docs/source/resources/define-metadata.rst +++ b/docs/source/resources/define-metadata.rst @@ -1931,7 +1931,10 @@ variables are booleans. - True if the platform is either macOS or Windows and the Python architecture is arm64. * - unix - - True if the platform is either macOS or Linux or emscripten. + - True if the platform is either macOS or Linux or emscripten + or FreeBSD. + * - freebsd + - True if the platform is FreeBSD. * - win - True if the platform is Windows. * - win32 From a1b5675cb356d8966d2d29546002fcc75d766552 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Fri, 5 May 2023 20:48:40 -0500 Subject: [PATCH 6/7] add news item --- news/4872-add-freebsd-support | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 news/4872-add-freebsd-support diff --git a/news/4872-add-freebsd-support b/news/4872-add-freebsd-support new file mode 100644 index 0000000000..27a9437ee6 --- /dev/null +++ b/news/4872-add-freebsd-support @@ -0,0 +1,19 @@ +### Enhancements + +* Add support for FreeBSD. (#4872) + +### Bug fixes + +* + +### Deprecations + +* + +### Docs + +* + +### Other + +* From 42b95535e1027872e6501d8710b4f96ae681557f Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Mon, 16 Oct 2023 11:19:02 -0500 Subject: [PATCH 7/7] make one condition for .so --- conda_build/environ.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/conda_build/environ.py b/conda_build/environ.py index d067c68257..f07ed6356d 100644 --- a/conda_build/environ.py +++ b/conda_build/environ.py @@ -581,9 +581,7 @@ def get_shlib_ext(host_platform): return ".dll" elif host_platform in ["osx", "darwin"]: return ".dylib" - elif host_platform.startswith("linux") or host_platform.endswith("-wasm32"): - return ".so" - elif host_platform.startswith("freebsd"): + elif host_platform.startswith(("linux", "freebsd")) or host_platform.endswith("-wasm32"): return ".so" elif host_platform == "noarch": # noarch packages should not contain shared libraries, use the system