Skip to content

Commit

Permalink
dart.rhttp: init
Browse files Browse the repository at this point in the history
  • Loading branch information
aucub committed Nov 11, 2024
1 parent 4aa3656 commit 9716e3c
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
matrix = callPackage ./matrix { };
media_kit_libs_linux = callPackage ./media_kit_libs_linux { };
olm = callPackage ./olm { };
rhttp = callPackage ./rhttp { };
sqlcipher_flutter_libs = callPackage ./sqlcipher_flutter_libs { };
sqlite3 = callPackage ./sqlite3 { };
system_tray = callPackage ./system-tray { };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
--- old/cargokit/cmake/cargokit.cmake 2024-11-08 13:36:13.345889693 +0800
+++ new/cargokit/cmake/cargokit.cmake 2024-11-08 13:45:26.019632176 +0800
@@ -17,83 +17,22 @@
function(apply_cargokit target manifest_dir lib_name any_symbol_name)

set(CARGOKIT_LIB_NAME "${lib_name}")
- set(CARGOKIT_LIB_FULL_NAME "${CMAKE_SHARED_MODULE_PREFIX}${CARGOKIT_LIB_NAME}${CMAKE_SHARED_MODULE_SUFFIX}")
- if (CMAKE_CONFIGURATION_TYPES)
- set(CARGOKIT_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>")
- set(OUTPUT_LIB "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${CARGOKIT_LIB_FULL_NAME}")
- else()
- set(CARGOKIT_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
- set(OUTPUT_LIB "${CMAKE_CURRENT_BINARY_DIR}/${CARGOKIT_LIB_FULL_NAME}")
- endif()
- set(CARGOKIT_TEMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/cargokit_build")
-
- if (FLUTTER_TARGET_PLATFORM)
- set(CARGOKIT_TARGET_PLATFORM "${FLUTTER_TARGET_PLATFORM}")
- else()
- set(CARGOKIT_TARGET_PLATFORM "windows-x64")
- endif()
-
- set(CARGOKIT_ENV
- "CARGOKIT_CMAKE=${CMAKE_COMMAND}"
- "CARGOKIT_CONFIGURATION=$<CONFIG>"
- "CARGOKIT_MANIFEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/${manifest_dir}"
- "CARGOKIT_TARGET_TEMP_DIR=${CARGOKIT_TEMP_DIR}"
- "CARGOKIT_OUTPUT_DIR=${CARGOKIT_OUTPUT_DIR}"
- "CARGOKIT_TARGET_PLATFORM=${CARGOKIT_TARGET_PLATFORM}"
- "CARGOKIT_TOOL_TEMP_DIR=${CARGOKIT_TEMP_DIR}/tool"
- "CARGOKIT_ROOT_PROJECT_DIR=${CMAKE_SOURCE_DIR}"
- )
-
- if (WIN32)
- set(SCRIPT_EXTENSION ".cmd")
- set(IMPORT_LIB_EXTENSION ".lib")
- else()
- set(SCRIPT_EXTENSION ".sh")
- set(IMPORT_LIB_EXTENSION "")
- execute_process(COMMAND chmod +x "${cargokit_cmake_root}/run_build_tool${SCRIPT_EXTENSION}")
- endif()
-
- # Using generators in custom command is only supported in CMake 3.20+
- if (CMAKE_CONFIGURATION_TYPES AND ${CMAKE_VERSION} VERSION_LESS "3.20.0")
- foreach(CONFIG IN LISTS CMAKE_CONFIGURATION_TYPES)
- add_custom_command(
- OUTPUT
- "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG}/${CARGOKIT_LIB_FULL_NAME}"
- "${CMAKE_CURRENT_BINARY_DIR}/_phony_"
- COMMAND ${CMAKE_COMMAND} -E env ${CARGOKIT_ENV}
- "${cargokit_cmake_root}/run_build_tool${SCRIPT_EXTENSION}" build-cmake
- VERBATIM
- )
- endforeach()
- else()
- add_custom_command(
- OUTPUT
- ${OUTPUT_LIB}
- "${CMAKE_CURRENT_BINARY_DIR}/_phony_"
- COMMAND ${CMAKE_COMMAND} -E env ${CARGOKIT_ENV}
- "${cargokit_cmake_root}/run_build_tool${SCRIPT_EXTENSION}" build-cmake
- VERBATIM
- )
- endif()
-
-
- set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/_phony_" PROPERTIES SYMBOLIC TRUE)

if (TARGET ${target})
# If we have actual cmake target provided create target and make existing
# target depend on it
- add_custom_target("${target}_cargokit" DEPENDS ${OUTPUT_LIB})
+ add_custom_target("${target}_cargokit" DEPENDS OUTPUT_LIB)
add_dependencies("${target}" "${target}_cargokit")
- target_link_libraries("${target}" PRIVATE "${OUTPUT_LIB}${IMPORT_LIB_EXTENSION}")
+ target_link_libraries("${target}" PRIVATE OUTPUT_LIB)
if(WIN32)
target_link_options(${target} PRIVATE "/INCLUDE:${any_symbol_name}")
endif()
else()
# Otherwise (FFI) just use ALL to force building always
- add_custom_target("${target}_cargokit" ALL DEPENDS ${OUTPUT_LIB})
+ add_custom_target("${target}_cargokit" ALL DEPENDS OUTPUT_LIB)
endif()

# Allow adding the output library to plugin bundled libraries
- set("${target}_cargokit_lib" ${OUTPUT_LIB} PARENT_SCOPE)
+ set("${target}_cargokit_lib" OUTPUT_LIB PARENT_SCOPE)

endfunction()
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
lib,
rustPlatform,
stdenv,
}:

{ version, src, ... }:

let
rustDep = rustPlatform.buildRustPackage {
pname = "rhttp-rs";
inherit version src;

sourceRoot = "${src.name}/rust";

cargoHash =
{
_0_9_1 = "sha256-Gl3ArdSuw3/yi/JX6oloKJqerSJjTfK8HXRNei/LO+4=";
}
.${"_" + (lib.replaceStrings [ "." ] [ "_" ] version)} or (throw ''
Unsupported version of pub 'rhttp': '${version}'
Please add cargoHash here. If the cargoHash
is the same with existing versions, add an alias here.
'');

env.RUSTFLAGS = "--cfg reqwest_unstable";

passthru.libraryPath = "lib/librhttp.so";
};

in
stdenv.mkDerivation {
pname = "rhttp";
inherit version src;
inherit (src) passthru;

patches = [ ./cargokit.patch ];

postPatch = ''
substituteInPlace ./cargokit/cmake/cargokit.cmake --replace-fail "OUTPUT_LIB" "${rustDep}/${rustDep.passthru.libraryPath}"
'';

installPhase = ''
runHook preInstall
mkdir $out/
cp -r ./* $out/
runHook postInstall
'';
}

0 comments on commit 9716e3c

Please sign in to comment.